Last active
March 23, 2022 12:22
-
-
Save AnkitMaheshwariIn/0d494dce9b36f28ff72e8a992f582187 to your computer and use it in GitHub Desktop.
travers an array
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
/* RUN THIS CODE AND OPEN YOUR CONSOLE TO SEE THE OUTPUT */ | |
// declare an array | |
arr = [10, 20, 30, 40, 50] | |
// travers an array | |
for (i = 0; i < arr.length; i++) { | |
// travers means visiting each element once | |
console.log(`Element at index ${i} is ${arr[i]}`) | |
} | |
/* | |
THE OUTPUT IS: | |
"Element at index 0 is 10" | |
"Element at index 1 is 20" | |
"Element at index 2 is 30" | |
"Element at index 3 is 40" | |
"Element at index 4 is 50" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment