我有一个绑定到我的单击侦听器的函数,该函数将详细信息作为对象推送到数组(仅基于ID的唯一对象),但是当在同一元素和详细信息上收到点击时,我想弹出该元素已经存在于数组中。 例如:
var array=[
{id:124, value:"a", name:"e"},
{id:124, value:"b", name:"f"},
{id:125, value:"c", name:"g"},
{id:126, value:"d", name:"h"}
];
// I am using below to push unique elements, but here if the element is already present(based on ID) and again if request comes for insertion , i want to popup out that element. How do i achieve this ?
var newarray= array.filter((o, i) =>
array.findIndex(obj => obj.id == o.id) == i
);
答案 0 :(得分:0)