lodash: Get duplicate values from an array

前端 未结 12 2217
执念已碎
执念已碎 2020-12-09 08:14

Say I have an array like this: [1, 1, 2, 2, 3]

I want to get the duplicates which are in this case: [1, 2]

Does lodash support thi

12条回答
  •  抹茶落季
    2020-12-09 08:37

    Hope below solution helps you and it will be useful in all conditions

      hasDataExist(listObj, key, value): boolean {
        return _.find(listObj, function(o) { return _.get(o, key) == value }) != undefined;
      }
    
    
    
      let duplcateIndex = this.service.hasDataExist(this.list, 'xyz', value);
    

提交回复
热议问题