I have an array of objects, shown below. The first segment of code is within a loop where multiple objects of 'Item' are created and pushed onto the array.
Example of the problem is available here: http://jsfiddle.net/X6VML/
Notice how changing the value inside a textbox displays a duplicate item.
// class
var Item = function(label, value) {
this.Label = label;
this.Value = value;
};
var obj = new Item("My Label", "My Value");
// adds object onto array
itemArray.push(obj);
The problem I have is that the array can contain duplicate objects which I need to filter out before rending the list of objects into a table, shown below:
for (var i = 0; i < itemArray.length; i++) {
$('.MyTable').append("<tr><td>" + itemArray[i].Label + "</td><td>" + itemArray[i].Value + "</td></tr>");
}
I can identify whether it's a duplicate with the Value being the same. How can I filter the list of objects based on whether the Value already exists in the array?
Many thanks