I've been watching some courses and reading some lectures on JavaScript. I've seen that many web developers when they have an array or an object, to loop through it, they use the common for loop like this:
for (var i = 0; i < Things.length; i++) {
Things[i]
}
where Things
is an array or an object.
or this:
for (var i = Things.length; i--; ) {
Things[i];
}
others makes it even more complicated by using this:
for (var i = Things.length - 1; i >= 0; i--) {
Things[i]
}
and lately, I've found out that there's even a JQuery method to loop through arrays and objects:
$.each(Things, function (index,value){
// some code
});
but why using these four, while we have a more direct for loop
for arrays and object like the following:
for (var prop in Things) {
Things[prop]
}
is there anything behind this common practice? performance issues? any browser compatibility issues? anything at all?