I have the following script, I need to return the following result:
{
text: 'i love apples'
}, {
text: 'i eat my apple'
}, {
text: 'no apples on the table'
}
with the following script I get an error.
What am I doing wrong, how to fix it (also another solution without using .match could be fine too)?
Notes: search value could be different, so script should be re-usuable.
let data = [{
text: 'i love apples'
}, {
text: 'i eat my apple'
}, {
text: 'no apples on the table'
},{
text: 'i love oranges'
}];
let search = 'apple'
let filter = data.filter(item=>{ return item.match(search)})
console.log(filter)
item.text.match(search)?