JS中两个数组去重合并

时间:2022-09-03 17:43:25
 
function get(datas) {
  let resourceDatas = [];
  for (let i = 0; i < datas.length; i++)
  {
      let targetResource = datas[i];
      if (targetResource.type == Define.RESOURCE_TYPE_GUEST_DEVICE)
          continue;
      resourceDatas.push(targetResource);
  }

  let arrObj = {};
  resourceDatas.map((e) => {
    arrObj[e.id] = e;
  })

  let keys = [];
  for (let property in arrObj) {
    keys.push(arrObj[property]);
  }

  if (keys.length == 1) {
    shortName = resourceDatas[0].shortName;
    this.selectResourceId = resourceDatas[0].id;
    this.selectResourceName = resourceDatas[0].shortName
    $("#divId").find("tr").eq(1).click();
  } else {
    this.btnExcuteTopFlag = 2;
  }

  resourceDatas = keys; // merge result
}