检查数组重复(一)
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

Logo

前往低代码交流专区

更多推荐