Javascript array forEach

<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/>");

Few notes on Javascript array forEach

  1. Array arr is passed to function as local variable a
  2. Array arr is also available in function here as it happened to be a global variable.
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments