I'm sure there is an easy answer for this, though I only really have experience with PHP. Why does the "pizza" array change when I pass it to my function as "my_pizza" and only make changes to "my_pizza"? How do I keep my original array I pass to the function outside of the function? Once the function is finished running, the pizza array should have not changed. I noticed if I change my string variable (pie) it will stay the same after the function runs, unlike the array.
In short, I want the first set of results to be identical to the second.
var pizza = []; pizza.push('crust'); pizza.push('ham'); var pie = "apple" function bake_goods(my_pizza, my_pie){ console.log(my_pizza); console.log(my_pie); delete my_pizza['1']; my_pie = "peach"; console.log(my_pizza); console.log(my_pie); } //first run bake_goods(pizza, pie); //console logs //['crust','ham'] //apple //['crust'] //peach //second run bake_goods(pizza, pie); //console logs //['crust'] //apple //['crust'] //peach
Array#splice, notdelete.Array.prototype.splice, which you actualy invoke assomeArr.splice(). (It's not actually valid syntax.)