I have details of the students; how to get my expected output? In one object I want the name of the student as key and an array of their car names as value
let empArray = [{
"name": "soma",
"cars Details": [{
"name": "audi",
"cost": 120000,
"Speed": "150Km/hr"
}, {
"name": "toyota",
"cost": 120000,
"Speed": "150Km/hr"
}],
"salary": 40000
},
{
"name": "steven",
"cars Details": [{
"name": "bmw",
"cost": 120000,
"Speed": "150Km/hr"
}],
"salary": 70000
},
{
"name": "booth",
"cars Details": [{
"name": "swift",
"cost": 120000,
"Speed": "150Km/hr"
}, {
"name": "audi",
"cost": 120000,
"Speed": "150Km/hr"
}],
"salary": 35000
},
]
let a = {}
var ids = [];
for (let i = 0; i < empArray.length; i++) {
a = empArray[i]["cars Details"]
console.log(a)
}
Expected Output
{soma :["audi","toyota"],steven:["bmw"],booth:["swift","audi"]}