Remove Duplicate from array object

Hi guys,
I have a array like this:

test = [{ 'id': '1231', 'value': '111111' },
  { 'id': '1232', 'value': '111111' },
  { 'id': '1233', 'value': '21121' },
  { 'id': '1234', 'value': '22222' },
  { 'id': '1235', 'value': '555555' },
  { 'id': '1236', 'value': '555555' },
  ]

it has duplicate object
i want to remove these duplicates from test array.
want new array like this:

newArray= [{ 'id': '1231', 'value': '111111' },
  { 'id': '1233', 'value': '21121' },
  { 'id': '1234', 'value': '22222' },
  { 'id': '1235', 'value': '555555' },
  ]

please, guys, help
thanks

try this

Try this:

function myFunction() {
    var test = [{ 'id': '1231', 'value': '111111' },
  { 'id': '1232', 'value': '111111' },
  { 'id': '1233', 'value': '21121' },
  { 'id': '1234', 'value': '22222' },  
  { 'id': '1235', 'value': '555555' },
  { 'id': '1236', 'value': '555555' },
  ]
var new_test = [{'id': '', 'value': ''}];
new_test[0].value=test[0].value;
new_test[0].id=test[0].id;

for (var i = 0; i <= test.length - 1; i++) {
var duplicate = false;  
	for(var j = new_test.length - 1; j >= 0; j--){
    	if(test[i].value == new_test[j].value) duplicate = true;
    }
if(!duplicate) new_test.push(test[i]);

} 
    alert(JSON.stringify(new_test));
}
1 Like

thank u so much its works

Thank you. this is what I am looking for. :blush: