admin管理员组

文章数量:1297016

I have a multi dimentional array as following. I need to delete the previous row if the value of the particular key value duplicates

[
  {"id":5, "name":"abc"}
  {"id":5, "name":"abcd"}
  {"id":6, "name":"abcde"}
]

I need to get the result as following after deleting the previous row if the value of id already exists.

[
  {"id":5, "name":"abcd"}
  {"id":6, "name":"abcde"}
]

I have a multi dimentional array as following. I need to delete the previous row if the value of the particular key value duplicates

[
  {"id":5, "name":"abc"}
  {"id":5, "name":"abcd"}
  {"id":6, "name":"abcde"}
]

I need to get the result as following after deleting the previous row if the value of id already exists.

[
  {"id":5, "name":"abcd"}
  {"id":6, "name":"abcde"}
]
Share Improve this question asked Feb 22, 2018 at 8:05 HareeshHareesh 1,5874 gold badges21 silver badges48 bronze badges 4
  • 2 Do you want to always remove the previous row or just the existing row that has similar id? – Giovanni Lobitos Commented Feb 22, 2018 at 8:07
  • is there only one dupe? do you want only the last one if one or more dupes? what have you tried? – Nina Scholz Commented Feb 22, 2018 at 8:07
  • its not clear from your question by what rules/criteria you want to remove a lookalike array (syntactically they're not duplicate). – izengod Commented Feb 22, 2018 at 8:12
  • @GiovanniLobitos and NinaScholz It may have more than one array with same id and i always want to remove the previous row and keep the last row. – Hareesh Commented Feb 22, 2018 at 8:53
Add a ment  | 

2 Answers 2

Reset to default 10

Map can be leveraged to produce a pretty cool one-liner

本文标签: ReactJSJavascript How to remove the duplicate array from multi dimentional arrayStack Overflow