I have code as follows:
data = [
{id: "15130", state: "INITIAL"},
{id: "15129", state: "LOCKED"},
{id: "10314", state: "APPROVED"},
{id: "51", state: "APPROVED"},
{id: "10313", state: "APPROVED_LOCKED"},
{id: "10315", state: "APPROVED_LOCKED"}
]
filters = [{id: "2", name: "LOCKED", count: 2}]
let result = []
_.forEach(data, (ca) => {
if (filters.length > 0) {
if (!_.some(filters, (item) => item.name === ca.state.includes('LOCKED') ? "LOCKED" : ca.state))
return;
}
result.push(ca);
});
console.log(result)
I want to get all records from data where state includes "LOCKED". Thus result should be:
result = [
{id: "15129", state: "LOCKED"},
{id: "10313", state: "APPROVED_LOCKED"},
{id: "10315", state: "APPROVED_LOCKED"}
]
But I get all records in result.
Any idea what I do wrong?
counthave a meaning here?namewhat matters.