Copy an array in Javascript by value, not by reference
Sam Ciaramilaro • April 9, 2015
Snippetsvar food = ['pizza', 'pasta', 'meatballs'];
var foodAgain = food.slice();
foodAgain.push("lasagna");
console.log(foodAgain); // ['pizza', 'pasta', 'meatballs']
console.log(food); // ['pizza', 'pasta', 'meatballs', 'lasagna']