I am working with two arrays, array A and array B
Here is how they look:
A:
[11, 14]
B:
[
{ title: 'title 1', data: [ { node_id: 11, selected: false }, { node_id: 14, selected: false } ]},
{ title: 'title 2', data: [ { node_id: 70, selected: false } ]}
]
This is the code I have written:
B.map((value) => {
A.map((selectedDeviceId) => {
value.data.map((valueData) => {
selectedDeviceId === valueData.node_id
? (valueData.selected = true)
: (valueData.selected = false);
});
});
});
However, when I check the B array, the output is:
[
{ title: 'title 1', data: [ { node_id: 11, selected: false }, { node_id: 14, selected: true } ]},
{ title: 'title 2', data: [ { node_id: 70, selected: false } ]}
]
I expected it to be:
[ { node_id: 11, selected: true }, { node_id: 14, selected: true } ]
Can you spot what's wrong in my code?