I would like to know which one is most suitable for working with arrays?
var meu_array = new Array(1, 2, 3);
var meu_array = [1, 2, 3];
Is there any performance difference between the 6 cases presented in the use of loop below?
// foreach
meu_array.forEach(function(valor, i){
console.log(valor, i);
});
// for key associativa
for (var i in meu_array) {
console.log(meu_array[i], i);
}
// for valor associativo
var i = 0;
for (value of meu_array) {
console.log(value, i++);
}
// for interator
for (var i=0; i<=meu_array.length; i++) {
console.log(meu_array[i], i);
}
// while
var i=0;
while (i <= meu_array.length) {
console.log(meu_array[i], i);
i++;
}
// jquery
$.each(meu_array, function(i, value) {
console.log(value, i);
});