Iterating Array of Objects in javascript

后端 未结 9 1443
闹比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:04

    Using jQuery.each():

    var array = [
       {caste: "Banda", id: 4},
       {caste: "Bestha", id: 6}
    ];
        
    $.each(array, function( key, value ) {
      console.log('caste: ' + value.caste + ' | id: ' +value.id);
    }
    
    );

提交回复
热议问题