Create list of object members from object list

后端 未结 2 1307

Assume I have a list of objects like so:

var list = [
    { date: \'22/9/2016\', status: 1, id: \'11111\' },
    { date: \'23/9/2016\', status: 1, id: \'22222\'          


        
相关标签:
2条回答
  • 2021-01-22 16:46

    Use

    var ids = list.map(function(item) { return item.id});
    

    Should work.

    0 讨论(0)
  • 2021-01-22 17:02

    You can use Array map

    var list = [
        { date: '22/9/2016', status: 1, id: '11111' },
        { date: '23/9/2016', status: 1, id: '22222' },
        { date: '24/9/2016', status: 1, id: '33333' }
    ];
    var idList = list.map(item => item.id );
    console.log(idList);

    0 讨论(0)
提交回复
热议问题