How do you loop through objects in an array?
Explanation
The correct way to loop through an object in an array.
Correct way to loop through object in an array:
var myArray = ['object1','object2','object3'];
for (var i=0; i < myArray.length;i++){
   //do something
}
and the second option is:
for (i in [1,2,3]) console.log ([i])

@xalexvp02 @basimdev32 Thanks! fixed question

2018 Feb 4, 5:26:39 PM

Actually, it's not true because when go for (I in arr) we will get index in i, so inside a loop we can use arr[i] to access an item.

2018 Jan 24, 6:26:25 PM

[1,2,3].__proto__.__proto__ //(Object) a = [1,2,3] (3) [1, 2, 3] for (i in a) console.log ([i]) ["0"] ["1"] ["2"] for (i in [1,2,3]) console.log ([i]) ["0"] ["1"] ["2"]

2018 Jan 21, 7:16:16 PM

Fix it! The end of the answer is cut off!

2017 Jun 1, 8:42:10 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback