I have two arrays,
let student = [{ id: "weqwe", name: "john" }, { id: "wqeqweq", name: "doe" }]
let details = [
{ id: "2qweqweq", name: "larry", oName: "john" },
{ id: "231234qa", name: "jacob", oName: "john" },
{ id: "wetyrqwte", name: "jane", oName: "doe" }
]
I need to check through each object in details array and compare it with student array (compare with oName property in details array with name property in student array) and need to add an array of the details as on object property. Also need to remove the oName, I have tried in es6 but dynamically creating array and pushing gives only the last value, Please see the below expected output,
let output = [
{
id: "weqwe",
name: "john",
details: [
{ id: "2qweqweq", name: "larry" },
{ id: "231234qa", name: "jacob" }
]
},
{
id: "wqeqweq",
name: "doe",
details: [
{ id: "wetyrqwte", name: "jane" }
]
}
]
Thanks in advance !!