Iterating Array of Objects in javascript

后端 未结 9 1464
闹比i
闹比i 2020-12-24 13:31

I am having an array that consists the objects with a key, value how can we iterate each object for caste and id.

[
    Object {
           


        
9条回答
  •  星月不相逢
    2020-12-24 14:17

    In plain JavaScript you can do this:

    var array = [{caste: "Banda", id: 4}, {caste: "Bestha", id:6}];
    
    array.forEach(function(element, index) {
        console.log(element.id+" "+element.caste);
    });
    

    The callback function is called with a third parameter, the array being traversed. For learn more!

    So, you don't need to load jQuery library.

    Greetings.

提交回复
热议问题