This is bugging me quite a bit. I hope someone can help me with it. I'm doing this in React.
Here is the data (objects that have an array inside):
{
"Susan": {
"likes": [
"shopping",
"skiing",
"surfing"
],
"hates": [
"cycling",
"reading",
"cleaning"
]
},
"Andrew": {
"likes": [
"driving",
"hiking",
"coding"
],
"hates": [
"dancing",
"running",
"cleaning dishes"
]
}
}
Now, in this case, I would like to display/map both arrays ("likes" and "hates") based on user choosing "Susan" or "Andrew". I just can't seem to logical connect this.
Let's say user input is a variable:
let input = "Susan"
I have something like:
Object.values(data).filter((val) => {
if(input === val) {
return val;
}
}).map((obj) => {
return (
<div>
<p> {obj.likes} </p>
<p> {obj.hates} </p>
</div>
);
})
I know there has to be some kind of binding with the keys, but I don't know how to do that.
Your help is very much appreciated!