I am seeking a more streamlined method to merge these three arrays: two data arrays and a "cross" array that connects them.
3 Arrays
var drives = [
{"drivesId": "rwd", "name": "RWD"},
{"drivesId": "fwd", "name": "FWD"},
{"drivesId": "awd", "name": "AWD"}
]
var cars = [
{"carId": "civic", "name": "Civic"},
{"carId": "wrx", "name": "WRX"},
{"carId": "mustang", "name": "Mustang"},
{"carId": "focus", "name": "Focus"},
]
var drivesXcars = [
{"drivesXcars": "uid1", "carId": "civic", "drivesId": "fwd"},
{"drivesXcars": "uid2", "carId": "wrx", "drivesId": "awd"},
{"drivesXcars": "uid3", "carId": "mustang", "drivesId": "rwd"},
{"drivesXcars": "uid4", "carId": "focus", "drivesId": "fwd"},
]
I aim to consolidate them into a single array structured like this:
var carsComplete = [
{"drivesId": "fwd", "driveName": "FWD", "cars": [
{"carId": "civic", "name": "Civic"},
{"carId": "focus", "name": "Focus"}
]},
{"drivesId": "rwd", "driveName": "RWD", "cars": [
{"carId": "mustang", "name": "Mustang"}
]},
{"drivesId": "awd", "driveName": "AWD", "cars": [
{"carId": "wrx", "name": "WRX"}
]},
]
While I could achieve this using the standard for loop approach, I am looking for a more efficient solution as these arrays grow in size. The traditional "brute force" method doesn't suffice for me anymore.
If anyone knows of a more efficient way to accomplish this task using AngularJS and/or lodash, I would greatly appreciate your insight.