1

Possible Duplicate:
Copying array by value in javascript

How to copy an array of objects to another array in Javascript?

var qwerty1 = arr;
var qwerty2 = arr;

Both qwerty1 and qwerty2 may look different but point to the same reference. I read somewhere that "assigning a boolean or string to a variable makes a copy of that value, while assigning an array or an object to a variable makes a reference to the value." So my two arrays post different operations return the same objects.

Any light in this regard?

1
  • 1
    my array arr contains {objects}..So not a copy of the above link @RC. Commented Nov 28, 2011 at 6:43

1 Answer 1

2

The idiomatic way to copy an array in Javascript is to use concat:

var qwerty1 = arr.concat();
var qwerty2 = arr.concat();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.