JQuery Array Loop

From CoderLearner
Jump to: navigation, search

jQuery Loop Through Array Elements

Loop through array to access each array elements.

Example 1

Use for loop to access array elements.

$(document).ready(function() {
	var myIds =["app","app2","pp2",3,40];
	for(var i=0; i < myIds.length; i++)
	{
		alert(myIds[i]);
	}
});

Example 2

Use $.each to loop through array elements.

$(document).ready(function() {
	var myList =['apple','toshiba','nokea','lcd'];		
	$.each(myList,function(index,Element){
		alert(Element);
	})
});