I am currently struggling with this problem. I've been through numerous forums and websites and didn't get the answer. I would like to concatenate two objets in one array without merging using this car object constructor, :
const car = {
year: '',
model: '',
mileage: '',
available_colors: [1, 2, 3], // numbers indicate color id
};
var garage = [];
const honda = Object.create(car);
const volvo = Object.create(car);
honda.available_colors[1] = 34;
volvo.available_colors[0] = 80;
honda.year = 1987;
volvo.year = 1990;
garage.push(honda, volvo);
console.log(garage);
Problem is, here is the result i have :
console.log(garage[0].available_colors,garage[1].available_colors);
-->[80,2,3] , [80,2,3]
console.log(garage[0].year, garage[1].year);
-->1987 , 1990
The problem doesn't appear for the other parameters, only the array. How can i have two separate available_colors arrays that belong to each object separately?