一维数组为二维数组

setVisitProcess(source) {
    let data = [];
    let subData = [];
    for (let i = 0; i < source.length; i++) {
      const index = subData.indexOf(source[i].sceneName);
      if (index === -1) {
        subData.push(source[i].sceneName);
        data.push([source[i]]);
      } else {
        data[index].push(source[i]);
      }
    }
    return data;
  }
//循环数组   存储识别的参数  存在进行添加否则新建数组

你可能感兴趣的:(一维数组为二维数组)