我有一个 JSON 对象
[{id:1,name:a, cat:1},{id:1, name:a, cat:2},{id:2, name:b, cat:8}]
我需要它,这样我才能得到第一个重复的 id
[{id:1,name:a, cat:1},{id:2, name:b, cat:8}]
我有一个 JSON 对象
[{id:1,name:a, cat:1},{id:1, name:a, cat:2},{id:2, name:b, cat:8}]
我需要它,这样我才能得到第一个重复的 id
[{id:1,name:a, cat:1},{id:2, name:b, cat:8}]
I think you would need to create a loop and a new array for names, loop through each of the items, if its name doesn't already exist in the new array, add it to a new object for distinct values, and then add its name to the new array to make a comparison with later.
I'm not writing that code for you though, maybe you can have a crack at it yourself now you have a concept to work with. :)