Only add if not already in place
- by Woppie
Here's my data structure:
var data = [
{ id: '1924', info: 'boo' },
{ id: '1967', info: 'foo' }
];
The id value should be unique, but the info may not be unique. How would I add new data into the data hash only if the id of the new data is unique?
Is the only way to iterate over the whole hash and see if there is such an id already in place?
data.push({ id: '1967', info: 'goo-goo' }); //should not be added
data.push({ id: '1963', info: 'goo-goo' }); //should be added