从对象列表创建对象成员列表 [英] Create list of object members from object list
本文介绍了从对象列表创建对象成员列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个像这样的对象列表:
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' },
{ date: '24/9/2016', status: 1, id: '33333' }
];
我想创建上面列表中所有对象的ID列表,以便我最终得到:
I would like to create a list of the ids of all the objects in the above list, so that I end up with:
var idList = ['11111', '22222', '33333'];
显然,我可以遍历列表并手动构建idList。
是否有另一种方法可以通过本机JS,angularJS或其他库来实现。
Obviously, I could iterate through the list and build the idList manually. Is there an alternative way of doing this through either native JS, angularJS, or perhaps another library.
手动迭代列表并不是一个很大的开销,我只是想确保我不会忽略JS / angularJS的功能,而不是为我这样做。
Manually iterating through the list isn't a big overhead, I just want to ensure I'm not ignoring functionality of JS / angularJS that would do this for me instead.
推荐答案
您可以使用数组映射
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);
这篇关于从对象列表创建对象成员列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文