Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by RC., NickC, outis, meo, rob mayoff Jan 2 '12 at 7:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
my array arr contains {objects}..So not a copy of the above link @RC. –  Premanshu Nov 28 '11 at 6:43

1 Answer 1

up vote 2 down vote accepted

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

var qwerty1 = arr.concat();
var qwerty2 = arr.concat();
share|improve this answer
    
thanks Rob..... –  Premanshu Nov 28 '11 at 8:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.