【问题标题】:Array.prototype.includes() with an array of objects [duplicate]带有对象数组的 Array.prototype.includes() [重复]
【发布时间】:2021-02-01 18:47:40
【问题描述】:

This 这里的答案是关于如何使用 Array.prototype.includes() 过滤数组。有没有办法 像这样过滤对象:

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

与 Array.prototype.includes() 或类似的行为相同?我上面提供的链接的解决方案基本上过滤了一个字符串数组,并找到一个包含指定关键字的项目。谢谢。

【问题讨论】:

    标签: javascript arrays


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-01
      • 1970-01-01
      • 2019-07-04
      • 2018-05-09
      • 2018-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多