Skip to content

Instantly share code, notes, and snippets.

@ankitkanojia
Last active September 2, 2019 07:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ankitkanojia/45b77262bfe939984d3a31379ad9d926 to your computer and use it in GitHub Desktop.
Save ankitkanojia/45b77262bfe939984d3a31379ad9d926 to your computer and use it in GitHub Desktop.
Javascript or Jquery loop iterations, Different type of loop iterations.
var arrayCollection = [“ABC”, “DEF”, “HIJ”];
$.each(arrayCollection, function(index, value){
console.log(“index : “,index, “ value :”, value);
});
$(arrayCollection).each(function(index, value){
console.log(“index : “,index, “ value :”, value);
});
for(var i = 0; i < arrayCollection.length; i++) {
console.log(“index : “, i , “ value :”, arrayCollection[i]);
}
$.map(arrayCollection, function( val, i ) {
console.log(“index : “, i , “ value :”, val);
});
arrayCollection.map((val, i ) => console.log(“index : “, i , “ value :”, val));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment