I have defined object:
var obj = {
arr: [{prop1: 1}, {prop2: 2}]
}
Object is send to function to add some elements:
fnc(obj);
Where fnc looks like:
var fnc = function(p) {
p.arr.push({prop3: 3}); // doesn't work
p.arr[0].prop1 = 2; // works
p.arr.length = 0; // works
}
The problem is, that I'm able to change the current objects of obj's array, but I'm not able to add any elements. How can I add more elements to that array, that will be visible outside of this function?
p.arr.length = 0
? Just as an example of something that works? That's emptying your array... – Ben Flynn Jun 26 '13 at 23:18