Array objects jquery

I have an array of this kind.

0: {ID: 5, post_author: "1", post_date: "2017-10-26 13:02:24", post_date_gmt: "2017-10-26 13:02:24", post_content: "dfasdfasdfasdfasgfsgdsgdsfg", ?}
1:{ID: 1, post_author: "1", post_date: "2017-09-26 10:43:50", post_date_gmt: "2017-09-26 10:43:50", post_content: "Welcome to WordPress. This is your first post. Edit or delete it, then start writing!", ?}
2 : {ID: 4439, post_author: "1", post_date: "2017-05-12 09:11:51", post_date_gmt: "2017-05-12 09:11:51", post_content: "<p style="text-align: justify;"><b>During 2 days, ?}
3:{ID: 3970, post_author: "1", post_date: "2017-04-14 11:48:44", post_date_gmt: "2017-04-14 11:48:44", post_content: "<p style="text-align: justify;"><strong>April 10, ?.</p>?https://www.youtube.com/watch?v=iq437v6Z14o", ?}

how do I refer to each id in this array, and create a new array with the values I addressed

Answers 1

  • Have a look at Array.map to go over an array and create a new one with a "row transformer" callback. Or Array.forEach for simply looping over an array and do whatever you want.

    var array = [
        {ID: 1, val: "make"},
        {ID: 2, val: "an"},
        {ID: 3, val: "useful"},
        {ID: 4, val: "sample"},
        {ID: 5, val: "please"}
    ]
    
    var myNewArray = array.map(function(row, idx){
        return row.ID;
    });
    

Related Articles