All the examples that I have seen on this site suggest that I should be able to do this:
var multiArray = []
var singleArray = []
singleArray[0] = "10"
singleArray[1] = "11"
multiArray.push(singleArray)
singleArray[0] = "20"
singleArray[1] = "21"
multiArray.push(singleArray)
and I would expect multiArray to contain:
["10", "11"]["20", "21"}
In fact it contains:
["20", "21"]["20", "21"}
It looks as though multiArray holds a reference to singleArray rather than the data. So changing the contents of singleArray affects both entries in multiArray.
Have I made a very basic error or is there some workaround for this?
Thanks for any help.
multiArray.push([10,11], [20,21]). "It looks as though multiArray holds a reference to singleArray rather than the data." Yep, your are absolutely right.