array .prototype.includes()包含一个对象数组



这里的答案是关于如何使用array .prototype.includes()筛选数组。有办法吗像这样筛选对象:

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

具有与Array.prototype.includes()相同的行为或类似的东西?我上面提供的链接的解决方案基本上是过滤字符串数组,并找到其中具有指定关键字的项。谢谢。

试试这个:

const myArray = [ { title: 'bedroomoneone' }, { title: 'bedroomonetwo' }, { title: 'bathroom' } ];
const res = myArray.filter(({title}) => title.includes('bedroom'));
console.log(res);

最新更新