0

This answer here was about how to filter an array using Array.prototype.includes(). Is there a way to filter an object like this:

var myArray = [
{
  title: 'bedroomoneone',
},
{
  title: 'bedroomonetwo',
},
{
  title: 'bathroom',
},];

with the same behavior as Array.prototype.includes() or something similar? The solution to the link I provided above basically filters an array of strings and finds an item that has a specified keyword in it. Thanks.

user
  • 1,022
  • 2
  • 8
  • 30

1 Answers1

0

Try this:

const myArray = [ { title: 'bedroomoneone' }, { title: 'bedroomonetwo' }, { title: 'bathroom' } ];

const res = myArray.filter(({title}) => title.includes('bedroom'));

console.log(res);
Majed Badawi
  • 27,616
  • 4
  • 25
  • 48