Click here to Skip to main content
15,921,210 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have following string


and i want it as


in Jquery
Updated 5-Jun-20 2:45am

There is nothing built in for that...You must run a loop to check duplicates...
Here a sample for you to start with...
var json = [

var ids = [];
var clean = [];

$.each(json, function(index, value) {
    if($.inArray(, ids) == -1)

The ids array is a helper to check for duplicates and contains only the unique ids from the original array, where clean will hold the actual array with no duplicates...
Share this answer
Devraj Kapdi 10-Mar-15 7:38am    
Thank u Peter. i tried before with the same but it wont helped me . you solved my issue. thank u.
Kornfeld Eliyahu Peter 10-Mar-15 7:41am    
You're welcome...
Hafiz Muhammad Farooq 1-Jan-18 3:28am    
Peter, A perfect solution to remove duplicates. Thanks
function removeDuplicates(json_all) {
var arr = [],
collection = [];

$.each(json_all, function (index, value) {
if ($.inArray(, arr) == -1) {
return collection;
Share this answer
CHill60 5-Jun-20 8:48am    
No different to Solution 1 posted 5 years ago. Copying other members work and posting it as your own can lead to your account being closed. I suggest you delete this post.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900