Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

How do you use in for loops in JavaScript?

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
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x