Remove same Id or duplicate data from array

 let arrayFlat = [

{id:25 , name:"jaypal"},

{id:25 , name:"jaypal"},

{id:26 , name:"hello"},

{id:27 , name:"hi"}

]

 const output = [...new Map(arrayFlat.map(o => [o.id, o])).values()]


expected output:  let arrayFlat = [

{id:25 , name:"parmar"},


{id:26 , name:"hello"},


{id:27 , name:"hi"}

]

Comments

Post a Comment

Popular posts from this blog

Image Preview Before upload image into ReactJs

Format mobile number to this format "(845) 963-2545" #mobileFormat