Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

How do you use in for loops in JavaScript?

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

AjayDell10
VijayHP20
AmitLenovo30
[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
Tagged : / / /