将多个数组合二为一形成一个二维数组

pushing multiple arrays into one is forming a 2 dimensional array

以下代码返回 allRows[] 的长度为 3,因为它有 3 个数组。我正在尝试构建一个最终数组 allRows。

  getRows() {
    return this.element.all(by.css(".xyz")).getText();
  }

  getTotalRows() {
    const allRows = [];

    for (let i = 0; i < 3; i++) {
      allRows.push(this.getRows());
      this.scrollDown();
      this.waitToLoad();
    }
    return allRows;
  }

实际上 getRows() 正在返回一组承诺。对我的代码进行以下更改已解决问题

  getRows() {
    return this.pinnedRows.getText();
  }

  getTotalRows() {
    const defer = Promise.defer();
    let allRows = [];

    for (let i = 0; i < 3; i++) {
      this.getRows().then((rows) => {
        allRows = allRows.concat(rows);
        this.scrollDown();
        this.waitToLoad();
        if (i === 2) {
          defer.resolve(allRows);
        }
      });
    }
    return defer.promise;
  }

推加一个索引,你要的是concat()