I was coding in javascript and I needed to create an object with multiple sub-objects that would hold the same named variables. When I tried to push values to one sub-object, the others also would also get it. I simulated the behavior in the browser console as following:
object = {};
numbers = [0,1];
letters = ["a","b"]
fruits = ["peach", "pineapple"]
object.subObject1 = { numbers , letters , fruits };
object.subObject2 = { numbers , letters , fruits };
object.subObject1.numbers.push(3);
console.log(object.subObject2.numbers);
OUTPUT: [0, 1, 3]
So, when I push into the array1 sub-object. It also goes to the array2 sub-object, because apparently the numbers array is passed by reference. My question is, how can I do this so that they will keep the sub-object array property name ('numbers') but pass the array by value?