My Code:
<script type="text/javascript">
for each ( var movie in ['Endhiran The Robot','Shivaji The Boss','Anbulla Rajinikanth'] )
document.writeln(movies + "<br/>");
</script>
In Firefox, I am getting the output as
Endhiran The Robot
Shivaji The Boss
Anbulla Rajinikanth
But in IE9 and Chrome Version 23.0.1271.95 m, for each is not working and nothing is written on the document
There is no
for eachin JavaScript, that was a non-standard extension.There is the new ES5
forEachfunction, which is well supported in modern browsers although of course not in older ones:Several other options over in this other answer here on Stack Overflow. (The question mentions jQuery, but the answer covers both plain JavaScript and jQuery options.)