I am attempting to use Set.has
to filter an array in the following way:
const input = [
{ nick: 'Some name', x: 19, y: 24, grp: 4, id: '19340' },
{ nick: 'Some name', x: 20, y: 27, grp: 11, id: '19343' },
{ nick: 'Some name', x: 22, y: 27, grp: 11, id: '19344' },
{ nick: 'Some name', x: 22, y: 30, grp: 11, id: '19350' },
{ nick: 'Some name', x: 22, y: 12, grp: 23, id: '19374' },
{ nick: 'Some name', x: 22, y: 29, grp: 23, id: '19377' }
];
const grpToOmit = [ 11, 23 ];
const groupToOmitSet = new Set(grpToOmit);
input.filter(it => {
console.log(groupToOmitSet.has(it.grp))
return !groupToOmitSet.has(it.grp);
});
console.log(input)
After creating a collection of unique values from the grpToOmit
array, I check for them within the filter function.
Despite getting multiple true results in
console.log(groupToOmitSet.has(it.grp))
, this filter does not produce any changes to the input array.