Top "Foreach" questions

foreach is a looping construct that executes a given piece of code for each element in a list/collection/array.

For-each over an array in JavaScript

How can I loop through all the entries in an array using JavaScript? I thought it was something like this: …

javascript arrays loops foreach iteration
How does the Java 'for each' loop work?

Consider: List<String> someList = new ArrayList<String>(); // add "monkey", "donkey", "skeleton key" to someList for (String …

java foreach syntactic-sugar
Short circuit Array.forEach like calling break

[1,2,3].forEach(function(el) { if(el === 1) break; }); How can I do this using the new forEach method in JavaScript? I've tried …

javascript arrays foreach
How do you get the index of the current iteration of a foreach loop?

Is there some rare language construct I haven't encountered (like the few I've learned recently, some on Stack Overflow) in …

c# foreach
Invalid argument supplied for foreach()

It often happens to me to handle data that can be either an array or a null variable and to …

php foreach
How to find the foreach index?

Is it possible to find the foreach index? in a for loop as follows: for ($i = 0; $i < 10; ++$i) { echo $…

php loops foreach
For..In loops in JavaScript - key value pairs

I was wondering if there's a way to do something like a PHP foreach loop in JavaScript. The functionality I'm …

javascript foreach
jquery loop on Json data using $.each

I have the following JSON returned in a variable called data. THIS IS THE JSON THAT GETS RETURNED... [ {"Id": 10004, "PageName": "…

jquery json foreach
How to determine the first and last iteration in a foreach loop?

The question is simple. I have a foreach loop in my code: foreach($array as $element) { //code } In this loop, …

php loops foreach
foreach loop in angularjs

I was going through the forEach loop in AngularJS. There are few points that I did not understood about it. …

angularjs foreach