I'm trying to filter an array of objects by the summary nested property, if it includes the word Save in the summary prop value string. This is the array:
const issues = [{
id: '1',
key: 'CLS-1',
fields: {
summary: 'Save princess',
assignee: 'Mario',
}
},
{
id: '2',
key: 'CLS-2',
fields: {
summary: 'Save Mario',
assignee: 'Luigi',
}
},
{
id: '3',
key: 'CLS-3',
fields: {
summary: 'Kidnap princess',
assignee: 'Bowser',
}
},
{
id: '4',
key: 'CLS-3',
fields: {
summary: 'Get kidnap!',
assignee: 'Peach',
}
},
]
I have tried this one-liner:
const getItemsBySummary = items.filter(item => item.fields.includes('Save'));
But I get the error item.fields.includes is not a function. I'm guessing because fieldsis anobjectinstead of anarrayso it cannot run the methodincludes()`. However, I tried like so
const getItemsBySummary = items.filter(item => [item.fields].includes('Save'));
But I get an empty array. What am I doing wrong?