A simple solution would be:
var temp = [];
$.each(itemArray, function(index, obj){
var found = false;
$.each(temp, function(tempI, tempObj){
if(tempObj.Value == obj.Value){
found = true;
return false;
}
});
if(!found){
temp.push(obj);
}
});
itemArray = temp;
console.log(itemArray);
The above is simply iterating over each object in the array, and pushing it to the temp array if it's not already there, finally it overwrites itemArray
with temp
.
Have you considered eliminating duplicates at the point of adding to the array? Something like this:
function UniqueItemList(){
var items = [];
this.push = function(item){
for(var i=0; i<items.length; i++){
if(items[i].Value == item.Value){
return;
}
}
items.push(item);
};
this.getList = function(){
return items;
}
}
var myList = new UniqueItemList();
myList.push(new Item('label1', 'value1'));
myList.push(new Item('label2', 'value2'));
myList.push(new Item('label1', 'value1'));
myList.push(new Item('label1', 'value1'));
console.log(myList.getList());
If you try to push a duplicate item, it will be rejected.
Demo - here it is integrated into your code.