Created
September 4, 2021 02:11
-
-
Save cyberbarbie/6b4382c9907b5abac1bcd601340a7728 to your computer and use it in GitHub Desktop.
JavaScript forEach() to iterate list & output value and index updated by 1
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
let todos = ["Sleep", "Eat", "Pray", "Love"] | |
// Use forEach() to loop through array and print current index:value | |
todos.forEach((value, index) => console.log(`${index+=1}: ${value}`)) | |
// output: | |
/* | |
1: Sleep | |
2: Eat | |
3: Pray | |
4: Love | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment