pardon my English , i want to remove first element of an array of object if it occur twice
here is the array=[{id:34,value:45}, {id:23,value:35}, {id:34,value:28}]
i want to remove first element because third element's id is same as first element
output should be array=[{id:23,value:35}, {id:34,value:28}]
Object.values(array.reduce((acc, itm) => ({...acc, [itm.id]: {...itm}}), {}));. It iterates using.reduce, removes duplicates by keeping last element based onid, creates an intermediate object (resulting from.reduce) and gets theObject.valuesto get an array back. All of it - in one line. :-) PS: It uses shallow copy (by...spread-operator) so changes to the original array will not impact the result generated.