Skip to content

Instantly share code, notes, and snippets.

@gurucharanmk
Last active April 24, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gurucharanmk/88c7a2b18ff48d7baeae0ed4b42abe7b to your computer and use it in GitHub Desktop.
Save gurucharanmk/88c7a2b18ff48d7baeae0ed4b42abe7b to your computer and use it in GitHub Desktop.
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