I know how to remove an item from a json array, but I can't seem to make it work when adding.
The array:
var users = [
{name: 'james', id: '1'}
]
Want to add so it becomes:
var users = [
{name: 'james', id: '1'},
{name: 'thomas', id: '2'}
]
Here's the code for removing an array:
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);
//space removed
What changes would I need to make to reverse to add values to the array?