Last active
April 24, 2016 15:49
-
-
Save gurucharanmk/88c7a2b18ff48d7baeae0ed4b42abe7b 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
var Arr = [3, 6, 9, 12, 15, 18, 21]; | |
Arr.author="Gurucharan"; | |
//Using legacy for loop | |
console.log('==============[Legacy for loop]=============='); | |
for (var i = 0; i < Arr.length; ++i) { | |
console.log("index is of type", typeof i, Arr[i]); | |
} | |
//Using forEach | |
console.log('==============[for-each loop]=============='); | |
Arr.forEach(function (element, i) { //index i is optional | |
console.log("index is of type", typeof i, element); | |
}); | |
//Using for-in loop | |
console.log('==============[for-in loop]=============='); | |
for (i in Arr){ | |
console.log("index is of type", typeof i, Arr[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment