Do you think there is a big difference in for...in and for loops? What kind of "for" do you prefer to use and why?
Let's say we have an array of associative arrays:
var myArray = [{'key': 'value'}, {'key': 'value1'}];
So we can iterate:
for (var i = 0; i < myArray.length; i++)
And:
for (var i in myArray)
I don't see a big difference. Are there any performance issues?
myArray.forEach(callback[, thisarg])
. – Benji XVI Jan 6 '12 at 10:32if(myArray.hasOwnProperty(i)){true}
– Eric Hodonsky Mar 27 '12 at 22:18['foo', 'bar', 'baz'].forEach(function(element, index, array){ console.log(element, index, array); });
is OK to use pretty much everywhere except in IE8- and it's by far the most elegant syntax – Jon z Sep 26 '12 at 17:51for...of
statement in ECMAScript 6, for example:for (let i of myArray) console.log(i);
– Vitalii Fedorenko May 5 '15 at 23:01