【问题标题】:How to check if table include more than 1 the same attribute? [duplicate]如何检查表是否包含超过 1 个相同的属性? [复制]
【发布时间】:2018-01-31 17:32:12
【问题描述】:

atm 我正在学习 JS/Angular 并使用这些技术制作项目,我需要一些帮助。

table = ['a', 'b', 'c', 'a'];

if(table.includes('a' > 2))  #its not working, idk how to make it
{
   console.log("We have 2 the same atributes in our table");
}

如何实现?

【问题讨论】:

    标签: javascript include


    【解决方案1】:

    你可以过滤数组并检查它的长度

    if(table.filter(item => item === 'a').length > 1) {
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多