Retrieve the latest entries from the array with identical ids:
Input:
[{id:1,name:"Java"},{id:1,name:"JavaScript"},{id:1,name:"Python"},{id:1,name:"C++"},{id:2,name:"C"},{id:2,name:"Ruby"},{id:2,name:"Php"}]
Desired Output:
[{id:1,name:"C++"},{id:2,name:"Php"}]
Attempted Solution:
array?.reverse().filter( (ele, ind) => ind === array.findIndex((elem) => elem?.id === ele?.id))
However, it resulted in the incorrect output
[{id:1,name:"Java"},{id:2,name:"C"}]