<script type="text/javascript"> var arr = ["v1", "v2"]; arr.forEach (function(item, idx, a) { document.write("idx=" + idx + " item=" + item + " a[idx]=" + a[idx] + " arr[idx]=" + arr[idx] + "<br/>"); }); </script>
Few notes on Javascript array forEach
- Array arr is passed to function as local variable a
- Array arr is also available in function here as it happened to be a global variable.