【发布时间】:2016-10-08 08:13:46
【问题描述】:
我有以下数组 例如,我只需要返回唯一 ID,因为在这个数组中我有 两次 id 1 & 3 我需要只有第一个 findigs id 的新数组,
在这个例子中,前 3 个条目,我如何将它与 maps/filter 一起使用,而不是与常规 for 一起使用
var oData = [{
id: 1,
ListTypeGroupDescription: 2,
test: 111,
test2: 222
}, {
id: 2,
ListTypeGroupDescription: 4,
test: 333,
test2: 444
}, {
id: 3,
ListTypeGroupDescription: 6,
test: 666,
test2: 777
}, {
id:1,
ListTypeGroupDescription: 99,
test: 666,
test2: 777
}, {
id: 3,
ListTypeGroupDescription: 99,
test: 666,
test2: 777
}];
var data = oData.map(
function(obj) {
return obj.id;
}
);
http://jsfiddle.net/5qu0j8g0/1/
地图只返回 ID,但我需要所有对象
我需要这个新数组
var oNew = [{
id: 1,
ListTypeGroupDescription: 2,
test: 111,
test2: 222
}, {
id: 2,
ListTypeGroupDescription: 4,
test: 333,
test2: 444
}, {
id: 3,
ListTypeGroupDescription: 6,
test: 666,
test2: 777
}
]
【问题讨论】:
-
请试试我的回答
标签: javascript arrays dictionary functional-programming