After numerous attempts using various methods, I am still unable to achieve the desired outcome. Even implementing nested ng-repeats in Angular to filter down to specific properties proved to be too resource-intensive.
My objective is to retrieve the value of "indices" for each object in the "groups" array, locate the corresponding object in the "person" array by matching the index with the 'indices' value, and then append that value to the respective object in the 'groups' array.
I am solely focused on accomplishing this task in JavaScript upon receiving a response from an API.
Here's an example:
var obj = {
"groups": [
{
"name": "GroupA",
"indices": [
0
]
},
{
"name": "GroupB",
"indices": [
1
]
},
{
"name": "GroupC",
"indices": [
2,
3
]
}
],
"person": [
{"name": "Archer"},
{"name": "Lana"},
{"name": "Mother"},
{"name": "Barry"}
]
};
Here is the expected final object structure:
var obj = {
"groups": [
{
"name": "GroupA",
"indices": [
0
],
"person": [
{"name": "Archer"}
]
},
{
"name": "GroupB",
"indices": [
1
],
"person": [
{"name": "Lana"}
]
},
{
"name": "GroupC",
"indices": [
2,
3
],
"person": [
{"name": "Mother"},
{"name": "Barry"}
]
}
]
};