Saturday 15 June 2013

javascript - Duplicate array -



javascript - Duplicate array -

i need duplicate , manipulate array variable, reason when force value newly created array pushing value original array.

function testing (point) { var newarray = currentchain; newarray.push(point); }

in situation, point beingness added currentchain variable. note setting currentchain equal newarray , there no other variables in script called newarray. why behaving way?

to prepare need clone array. illustration using slice method:

var newarray = currentchain.slice();

this happens because newarray pointer currentchain array.

javascript arrays variables duplicates

No comments:

Post a Comment