Remove Duplicate Object from JSON Array Remove Duplicate Object from JSON Array json json

Remove Duplicate Object from JSON Array


uniqueArray.indexOf doesn't work because you're comparing objects against strings (splitlen[i].name). Try to use .find() instead:

var arr1 = '[{"name":"Pune","city":"India"},{"name":"Pune","city":"India"}]';var splitlen = JSON.parse(arr1);var uniqueArray = [];var uniqueJson = {};for(i=0;i<splitlen.length;i++)    {                if(!uniqueArray.find(x => x.name === splitlen[i].name))            {                uniqueArray.push(splitlen[i]);            }    }console.log(uniqueArray);