Hi there, I'm new to Vue Js and I'm currently working on adding or merging new items in all JSON objects within an array that share the same value with another JSON object. I know how to push a new JSON object into an existing one, but I would really appreciate some advice on how to achieve this. Thank you in advance!
JSON 1 (Main)
[
{
name: "a",
id: 2,
price: 300
},
{
name: "b",
id: 3,
price: 100
},
{
name: "c",
id: 4,
price: 50
}
]
JSON 2 (List)
[
{
color: "red",
id: w2,
uuid: "3"
},
{
color: "blue",
id: y2,
uuid: "4"
},
{
color: "pink",
id: xf,
uuid: "3"
},
{
color: "black",
id: jf,
uuid: "7"
}
]
If the UUID of JSON 2 (List) matches the ID of JSON 1 (Main), I need to add another item in JSON 2 (List) inside an object named after the value of 'name' from JSON 1(Main), and remove any JSON objects in JSON 2 (List) whose UUID does not match any IDs in JSON 1 (Main). Here's an example of the expected output:
{
color: "black",
id: jf,
uuid: "7"
} //will be removed
Expected Output
[
{
name: "b",
color: "red",
id: w2,
uuid: "3"
},
{
name: "c",
color: "blue",
id: y2,
uuid: "4"
},
{
name: "b",
color: "pink",
id: xf,
uuid: "3"
}
]