use each function in jquery to example
Example 1: jquery each
$( "li" ).each(function( index ) {
console.log( index + ": " + $( this ).text() );
});
Example 2: jquery foreach
$.each( obj, function( key, value ) {
alert( key + ": " + value );
});
Example 3: foreach jquery
$( "li" ).each(function( index ) {
console.log( index + ": " + $( this ).text() );
});