If we need to use foreach loop in javascript then we can use jQuery $.each() function:
var data = [];
data[1] = "Mike";
data[2] = "Tom";
data[5] = "Harry";
data[12] = "John";
$.each(data, function( index, value ) {
alert( index + ": " + value );
});
If only javascript is required then following are the option to implement foreach in javascript:
1: forEach,
2: for-in
3: for-of
For complete reference in javascript Click Here .
0 Comment(s)