How to make an array unique by object key?
I have dynamic checkboxes, whose id I put in the state.
In the format [checkBoxId]: e.target.value
And then I try to make a unique array from the received checked from the checkbox, but nothing comes out
[...new Map(
myCheckboxes.map((item) => { // item {dfsd34534ftg: true} (dfsd34534ftg - id)
const key = Object.keys(item);
return [item[key], item];
}),
).values()]
{response.map(({ id}, idx) => (
<div key={id}>
<Checkbox
change={e => {
setMyCheckboxes(prev => [
...prev,
{
[id]: e.target.checked,
},
]);
}}
checked={myCheckboxes[idx]?.id}
/>
...