Created
September 22, 2017 09:34
-
-
Save imparvez/4803442610a1cc919811aede968df92c 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
// Different ways to loop or iterate arrays in JavaScript | |
var newArray = ['item 1', 'item 2', 'item 3', 'item 4']; | |
// Way no: 1 | |
for(var i = 0; i < newArray.length; i++) { | |
console.log('Array Item', newArray[i]); | |
} | |
// Way no: 2 | |
for(var i in newArray) { | |
console.log('Array Item: ', newArray[i]); | |
} | |
// Way no: 3 | |
newArray.forEach(function(value){ | |
console.log('Array Items: ', value); | |
}) | |
// Way no: 4 | |
newArray.map(function(value, index){ | |
console.log('Array Items => ', value); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment