vue中数组检测重复性的两个方法

检查数组重复(一)
let inputValue = this.positionGroupInput[groupId].inputValue;
  if (inputValue) {
    for (let positionGroup of this.lists) {
      if (positionGroup.id === groupId) {
        // 检查重复性
        let isExist = false;
        for (let position of positionGroup.positions) {
          (position.name === inputValue) {
            this.$message.error("职位名称不能重复");
              isExist = true;
            }
          }
        if (!isExist) {
          const newPosition = {groupId: groupId, id: this.generateId(), name: inputValue};
          positionGroup.positions.splice(positionGroup.positions.length, 0, newPosition);
          this.$message.success("添加职位成功")
        }
    }
  }
}

检查数组重复(二)
function displayDate(){
var arr = [{ d: '2015-10-12',C:'Apple'}, { d: '2015-10-12',C:'Apple'}, { d: '2015-10-13',C :'Apple' }];
var find = false;
for (var i = 0; i < arr.length; i++) {
  for (var j = i + 1; j < arr.length; j++) {
    if (arr[i].d == arr[j].d && arr[i].C==arr[j].C) {

     find = true; break;

      }

    }

  if (find) break;
  }
alert(find)
}

-------------------------------------------

个性签名:成功是分两半的,一半在上帝手中,那是宿命;另一半在自己手中,那是拼命。!

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!

原文地址:https://www.cnblogs.com/Front-endGraph/p/11304012.html