Answers for "why cant you loop through an array using -i"

8

loop through an array in javascript

const array = ["one", "two", "three"]
array.forEach(function (item, index) {
  console.log(item, index);
});
Posted by: Guest on May-31-2020
0

Iterating or loop through the elements of an array is with a for loop (for):

var keys = Object.keys(o);   // Get an array of property names for object o
var values = []              // Store matching property values in this array
for(var i = 0; i < keys.length; i++) {  // For each index in the array
    var key = keys[i];                  // Get the key at that index
    values[i] = o[key];                 // Store the value in the values array
}
Posted by: Guest on June-28-2021

Code answers related to "why cant you loop through an array using -i"

Code answers related to "Javascript"

Browse Popular Code Answers by Language