About 164,000 results
Open links in new tab
  1. Loop through an array in JavaScript - Stack Overflow

    Jun 10, 2010 · If you iterate over an array with for..of, the body of the loop is executed length times, and the loop control variable is set to undefined for any items not actually present in the array. Depending on the details of your "do something with" code, that behavior may be what you want, but if not, you should use a different approach.

  2. Loop (for each) over an array in JavaScript - Stack Overflow

    Feb 17, 2012 · forEach is the "loop through them all" function, but ES5 defined several other useful "work your way through the array and do things" functions, including: every ( spec | MDN ) - stops looping the first time the callback returns a falsy value

  3. How can I loop through a JavaScript object array?

    It appears you may just have missed the "messages" property in the data, so the loop is likely iterating the root Object rather than the Array: for (var key in data.messages) { var obj = data.messages[key]; // ... } Unless data was set to messages before the given snippet. Though, you should consider changing that to a normal for loop for the ...

  4. What's the fastest way to loop through an array in JavaScript?

    Mar 18, 2011 · If you don't have to reuse the array later, then while loop on decremented length and destructive shift()-ing array is also efficient. tl;dr Nowadays (2011.10) below pattern looks to be the fastest one.

  5. javascript - How to loop through an array containing objects and …

    The console should bring up every object in the array, right? But in fact it only displays the first object. if I console log the array outside of the loop, all the objects appear so there's definitely more in there. Anyway, here's the next problem. How do I access, for example Object1.x in the array, using the loop?

  6. javascript - looping through arrays of arrays - Stack Overflow

    Aug 18, 2011 · The outer loop would iterate the parent array, giving you one of the internal arrays each time. The inner loop would give you the items within each array. Example:

  7. What's the best way to loop through a set of elements in JavaScript?

    Oct 1, 2008 · I just tried to run a test to compare a simple iteration, the optimization I introduced and the reverse do/while, where the elements in an array was tested in every loop. And alas, no surprise, the three browsers I tested had very different results, though the optimized simple iteration was fastest in all !-)

  8. For loop in multidimensional javascript array - Stack Overflow

    Apr 5, 2012 · An efficient way to loop over an Array is the built-in array method .map() For a 1-dimensional array it would look like this: function HandleOneElement( Cuby ) { Cuby.dimension Cuby.position_x ... } cubes.map(HandleOneElement) ; // the map function will pass each element for 2-dimensional array:

  9. How to iterate (keys, values) in JavaScript? - Stack Overflow

    A basic doubt here. I landed here looking for how to do this in node.js, which is javascript on server side. How do I know which ES version applies in my case. Also, in case of regular javascript users, what is the proper way to support as I understand that ES version depends on the client's browser? –

  10. loops - How to iterate over a JavaScript object? - Stack Overflow

    Jan 17, 2013 · However, for..in will loop over all enumerable elements and this will not able us to split the iteration in chunks. To achieve this we can use the built in Object.keys() function to retrieve all the keys of an object in an array. We then can split up the iteration into multiple for loops and access the properties using the keys array. For example:

Refresh