If all your values in the state are JSON stringifiable, such as strings, booleans, numbers, null
, and arrays/objects that only contain JSON stringifiable values, then a fast approach exists with a set of JSON:
const issues = [{ id: 'foo', state: { label: 'bar'} }]
const states = [{ label: 'bar' }, { label: 'baz' }]
const stateSet = new Set(states.map(state => JSON.stringify(state)))
const filtered = issues.filter(issue => stateSet.has(JSON.stringify(issue.state)))
If you you can't stringify to JSON, then copy the deepCompare
function from this answer, and use that with some
:
const issues = [{ id: 'foo', state: { label: 'bar'} }]
const states = [{ label: 'bar' }, { label: 'baz' }]
function deepCompare() {
// ...
}
const filtered = issues.filter(issue => states.some(state => deepCompare(state, issue.state)))