У меня есть два массива, содержащие вложенные объекты. Я хотел бы объединить их и получить уникальный массив
У меня есть эти два массива
// ARRAY 1
let variants = [
{color: "Red", sizes: "Small", material: "Cotton", price: "$100", ...},
{color: "Red", sizes: "Large", material: "Cotton", price: "$120", ...},
{color: "Blue", sizes: "Small", material: "Cotton", price: "$150", ...},
{color: "Blue", sizes: "Large", material: "Cotton", price: "$180", ...},
]
// ARRAY 2
let newVariants = [
{color: "Red", sizes: "Small", material: "Cotton"}, // this one is already exist in ARRAY 1
{color: "Red", sizes: "Large", material: "Cotton"}, // this one is already exist in ARRAY 1
{color: "Blue", sizes: "Small", material: "Cotton"}, // this one is already exist in ARRAY 1
{color: "Blue", sizes: "Large", material: "Wool"}, // this one is new object
{color: "Green", sizes: "Large", material: "Cotton"}, // this one is new object
]
и я хочу этого
[
{color: "Red", sizes: "Small", material: "Cotton", price: "$100"},
{color: "Red", sizes: "Large", material: "Cotton", price: "$120"},
{color: "Blue", sizes: "Small", material: "Cotton", price: "$150"},
{color: "Blue", sizes: "Large", material: "Cotton", price: "$180"},
{color: "Blue", sizes: "Large", material: "Wool", price: null, ...},
{color: "Green", sizes: "Large", material: "Cotton", price: null, ...}
]
Примечание. Значение МАССИВА 1 всегда заменяет значение МАССИВА 2.
Спасибо!