MOTOSHARE 🚗🏍️

Rent Bikes & Cars Directly from Owners

Motoshare connects vehicle owners with people who need bikes and cars on rent. Owners earn from idle vehicles, and renters get flexible ride options.

Visit Motoshare

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
0
Would love your thoughts, please comment.x
()
x