How to iterate a JavaScript object's properties using jQuery?

Programming ScriptsjQueryFront End Technology

Use the each() method to iterate JavaScript object’s properties.

$.each( { name: "Amit", team: "India" }, function(n, l){
   alert( "The index is: " + n + ", Value: " + l );
});

The above prints −

The index is 0, Value: Amit
The index is 1, Value: India

The each() is used to iterate over any collection, whether it is an object or an array. Let’s see another example −

Example

$.each([ 100, 80 ], function( index, value ) {
   alert( index + " : " + value );
});

Output

The above prints −

0 : 100
1 : 80
raja
Published on 01-Mar-2018 10:24:08
Advertisements