-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday4Arrays.js
More file actions
50 lines (34 loc) · 815 Bytes
/
day4Arrays.js
File metadata and controls
50 lines (34 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// array
const names = ['Bhavani', 'Bhanu', 'Ramarao', 'Prabha', 'Ram'];
// array length
const arrLength = names.length;
console.log('array length:', names.length);
// traditional for loop
console.log('numbers less than 10')
for(let i = 0; i<10 ; i++){
console.log(i);
}
console.log('even numbers less than 20');
for(let i = 2; i<=20 ;i = i+2){
console.log(i);
}
// for loop on array
/***
*
*
* ['Bhavani', 'Bhanu', 'Ramarao', 'Prabha', 'Ram']
* 0 1 2 3 4
*
*
*
*
*/
console.log('names in the array');
for( let index = 0; index<arrLength; index++){
console.log(names[index]);
}
console.log('reverse order');
// print names in reverse order
for(let index = arrLength-1; index>=0;index = index--){
console.log(names[index]);
}