Currently I have an array like this:
const selected = [{a: 'john', b: 12}, {a: 'Paul', b: 12}]
And I want to set a constant called isSelected that be true if some object exists in that array.
Example:
const obj = {a: 'Paul', b: 12}
That object exists in the array.
I wanted to check it with:
const isSelected = selected.some((item) => item === obj);
Is not working, every items seems not be === to obj. I guess that some use a deeper comparisson than just the values. So, I'm using now this simple code:
let isSelected = false;
selected.forEach((sel) => {
if (
sel.a === obj.a
&& sel.b === obj.b
) { isSelected = true; }
});
It works but I wanted to know what better approach to use