for loop with Array
forEach Loop
The forEach calls a provided function once for each element in an array, in order.
Syntax: – array.forEach(function (value, index, arr) {
});
Where,
value – It is the current value of array index.
index – Array‟s index number
arr – The array object the current element belongs to
for of Loop
The for…of statement creates a loop iterating over iterable objects.
Syntax: –
for (var variable_name of array) {
}
Input from User in Array
You can get input from user in an empty array:-
- var geek= [ ];
- var geek = new Array( );
- var geek = new Array(3); // 3 is length of array
Multidimensional Array
Multidimensional array is Arrays of Arrays.
Multidimensional array can be 2D, 3D, 4D, etc.
Ex: –
2D – var name[ [ ], [ ], [ ]
Multidimensional Arra
Ajay | Dell | 10 |
Vijay | HP | 20 |
Amit | Lenovo | 30 |
[0][0] Ajay | [0][1] Dell | [2][1] 10 |
[0][0] Vijay | [1][1] HP | [2][1] 20 |
[2[0] Amit | [2][1] Zed | [2][2] 30 |