I've been able to successfully remove items from a JSON array, but I'm struggling with adding new items. Here's the current array:
var users = [
{name: 'james', id: '1'}
]
I want to add an item so the array looks like this:
var users = [
{name: 'james', id: '1'},
{name: 'thomas', id: '2'}
]
The code for removing an item from the array is as follows:
Array.prototype.removeValue = function(name, value){
var array = $.map(this, function(v,i){
return v[name] === value ? null : v;
});
this.length = 0; //clear original array
this.push.apply(this, array); //push all elements except the one we want to delete
};
removeValue('name', value);
What modifications do I need to make in order to add values to the array instead?