【发布时间】:2021-04-10 10:21:40
【问题描述】:
我有这种格式的数据
[["hi, hello, "bye"],["hi, hello, "bye"],["hi, hello, "bye"],["hi, hello, "bye"],["hi, hello, "bye"],["hi, hello, "bye"],["hi, hello, "bye"],["hi, hello, "bye"]]
我想将 4 个索引连接到新数组,所以新数组将是
[["hi, hello, "bye","hi, hello, "bye","hi, hello, "bye","hi, hello, "bye"],["hi, hello, "bye","hi, hello, "bye","hi, hello, "bye","hi, hello, "bye"]]
我正在尝试使用此代码,但不知道该怎么做
const table = document.querySelectorAll('table[class=ProductInventory]')[1];
const data = [];
const finalData =[]
for (var i = 1; i < table.rows.length; i++) {
var tableRow = table.rows[i];
var rowData = [];
for (var j = 0; j < tableRow.cells.length; j++) {
rowData.push(tableRow.cells[j].innerText);
}
data.push(rowData);
}
let counter = 1
for (var a = 0; a <= data.length / 4; a++) {
const obj = []
counter++
if(counter == 4){
obj.concat(data[a-3], data[a - 2], data[a - 1]);
counter = 0
}
finalData.push(obj)
}
【问题讨论】:
-
如果你不使用它返回的数组,那么调用
concat是没有意义的。
标签: javascript arrays json foreach transformation