Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  179] [ 1]  / answers: 1 / hits: 46652  / 12 Years ago, mon, august 6, 2012, 12:00:00

Possible Duplicate:

Array unique values

Get unique results from JSON array using jQuery






Im having a JSON string like this



[
Object { id=38,product=foo},
Object { id=38,product=foo},
Object { id=38,product=foo},
Object { id=39,product=bar},
Object { id=40,product=hello},
Object { id=40,product=hello}

]


There are duplicate values in this JSON array..how can i make this JSON array unique like this



[
Object { id=38,product=foo},
Object { id=39,product=bar},
Object { id=40,product=hello}
]


.Im looking for a suggestion that uses less iterations,
Jquery $.inArray is not working in this case.



Suggestion to use any third party libraries are welcome.


More From » jquery

 Answers
86

Check the solution in the following SO question:



Get unique results from JSON array using jQuery



You'll have to iterate through your array and create a new array which contains unique values.


[#83828] Saturday, August 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shane

Total Points: 239
Total Questions: 91
Total Answers: 114

Location: Faroe Islands
Member since Tue, Jul 7, 2020
4 Years ago
;