我有一个像这样的对象数组:
// other properties of the object omitted for brevity
// this array can potentially contain upto 50 objects like this
var myArray = [{url: 'http://linkA'}, {url: 'http://linkB'}, {url: 'http://linkA'}]
我正在尝试应用 reduce 函数来创建一个像这样的新对象:
var newArray = myArray.reduce(function(acc, current, index){
var newObj = {};
newObj['strata'] = 'kit';
newObj['href'] = current['url'];
acc.push(newObj);
return acc;
}, [])
但我不想包含重复的对象(使用对象的“url”属性测试的“重复”)。我如何修改我的 reduce 函数来跳过这些类型的对象并生成一个
[{strata: kit, href: 'http://linkA'}, {strata: kit, href: 'http://linkB'}]
编辑:对不起,我忘了提到这是遗留代码。我不能使用像“设置”和“一些”这样的功能
ITMISS
吃鸡游戏
不负相思意
相关分类