×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nilesh Yadav
Added: Jul 3, 2017 5:49 PM
Views: 3
Tags: no tags
  1. var fruits = ['apple', 'banana', 'orange', 'grapes', 'pear', 'passionfruit'];
  2.  
  3. // The three values on the callback function are:
  4. // element - The element being traversed
  5. // index - The current index of the item in the array starting at 0
  6. // array - The array being traversed (probably mostly irrelevant)
  7.  
  8. fruits.forEach(function(element, index, array) {
  9.     console.log(index, element);
  10. });