I have created a JavaScript object like below -
var objtvar = {defaultPoints: [[0,0],[0,-10],[2.5, -10], [2.5, -10],[5, -10],[5,0]]}
I need to assign the defaultPoints property to another array and modify this new array. However on updating this new array, the object property too gets updated.
I want the object property to not change.
Code -
var objtvar = {defaultPoints: [[0,0],[0,-10],[2.5, -10], [2.5, -10],[5, -10],[5,0]]};
var flag = objtvar.defaultPoints;
flag[5][1] = 9;
This updates the values in both flag array and the defaultPoints property. I do not wish the property to get updated.
Updated Solution - We can use the jquery extend suggested by @Nimrod Shory or use a pure JS implementation like this http://heyjavascript.com/4-creative-ways-to-clone-objects/