I have a array like this:
users = [{id:1, name:\'name1\'},{id:2, name:\'name2\'}]
How could I get a reference to the item {id:2, name:\'nam
Here is the code which will better explain the scenario. Run the script and will understand.
var arr = [
{"name": "James", "age": 34},
{"name": "Peter", "age": 67}
];
var p1 = arr.filter(function(p){return p.name=="James"});
p1[0] = {"name": "James", "age": 50};
console.log(JSON.stringify(arr)); // Won't work
var p2 = arr.filter(function(p){return p.name=="James"});
p2[0].age = 50;
console.log(JSON.stringify(arr)); // Voila... this works