Copy an array in Javascript by value, not by reference

Published in Code on Apr 9, 2015
var food = ['pizza', 'pasta', 'meatballs'];
var foodAgain = food.slice();

food.push("lasagna");

console.log(foodAgain); // ['pizza', 'pasta', 'meatballs', 'lasagna']
console.log(food); // ['pizza', 'pasta', 'meatballs']