Created
November 2, 2020 15:00
-
-
Save ranamahmud/76e674ff947e084f8133a60abf029025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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