Copying an array of objects into another array in javascript
How can I copy every element of an array (where the elements are objects), into another array, so that they are totally independent? I don't want changing an element in one array to affect the other. If the destination array doesn't exist yet... ...you can use slice() or concat() . slice() is probably more idiomatic (you'll also see slice(0) , but the default is 0, so...): var destinationArray = sourceArray.slice(); // Probably more idiomatic // or var destinationArray = sourceArray.concat(); As of ES2015 (aka ES6), there's also Array.from , which creates a new array from any array-like thing