Skip to content

Instantly share code, notes, and snippets.

@ranamahmud
Created November 2, 2020 15:00
Show Gist options
  • Save ranamahmud/76e674ff947e084f8133a60abf029025 to your computer and use it in GitHub Desktop.
Save ranamahmud/76e674ff947e084f8133a60abf029025 to your computer and use it in GitHub Desktop.
// declare an array
var fruits = ["apple", "orange", "banana", "pineapple"]
// loop over with items
fruits.forEach(function(fruit){
console.log(fruit);
})
// output
// apple
// orange
// banana
// pineapple
// loop over with item and index
fruits.forEach(function(fruit,index){
console.log("index: "+index+ " " + fruit);
})
// output
// index: 0 apple
// index: 1 orange
// index: 2 banana
// index: 3 pineapple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment