Let’s say I have a category for which I need to pull out the values.
const users = ["user1","user2","user 3"];
The main object structure is
const userInfo = [
{"name":"user1", "gender":"female","ageGroup":"millenial", "subjects":["physics","history"], "value": 0.3
},
{"name":"user2", "gender":"male","ageGroup":"gen z", "subjects":["physics","history"], "value": 0.3
},
{"name":"user1", "gender":"female","ageGroup":"millenial", "subjects":["math","history"], "value": 0.5
},
{"name":"user3", "gender":"male","ageGroup":"gen a", "subjects":["history","math"], "value": 0.4
}
{"name":"user2", "gender":"male","ageGroup":"gen z", "subjects":["physics","math"], "value": 0.7
},
];
Now I want to I take a category variable “users” for example, and it should, in the same order of the variable output the value in an array of arrays.
If I pass users, the expected output is:
[
[0.3,0.5],//user1
[0.3,0.7],//user2
[0.4]//user3
]
The order cannot be user 2, and then user 1.
I think this would work best as a function, but I’m open to simple operations as well. If you could explain the code it’d be great so I can learn to do this on my own in the future 🙂