I am new to JavaScript here. I am trying to create a variable duplicated from a object property. When I make changes to the new variable, the original variable is also changed. How can I break the link between the two variables?
For instance,
var a = {};
a.data = ["a", "b", "c", "d"];
var b = a.data;
b.splice(0,1);
The output looks like the following.
> b
> ["b", "c", "d"]
> a.data
> ["b", "c", "d"]
What I expect is this.
> b
> ["b", "c", "d"]
> a.data
> ["a", "b", "c", "d"]