mergeSpan(tableData, arr) { //["areName","indexCode"] let spanArr = new Array(tableData.length); for (let m = 0; m < spanArr.length; m++) { spanArr[m] = new Array(arr.length); } arr.forEach((ele, ind) = > { let pos = null; tableData.forEach((item, index, self) = > { if (index == 0) { spanArr[index][ind] = { rowspan: 1, colspan: 1 } pos = 0; } else { if (item[ele] === self[index - 1][ele]) { spanArr[pos][ind].rowspan += 1; spanArr[index][ind] = { rowspan: 0, colspan: 0 } } else { pos = index; spanArr[index][ind] = { rowspan: 1, colspan: 1 } } } }) }) tableData.forEach((item, index) = > { let pos = null; arr.forEach((ele, ind, self) = > { if (ind == 0 && spanArr[index][ind].rowspan == 1) { spanArr[index][ind].colspan = 1; pos = 0; } else { if (item[ele] == item[self[ind - 1]] && spanArr[index][pos].rowspan == 1) { spanArr[index][pos].colspan += 1; spanArr[index][ind] = { rowspan: 0, colspan: 0 } } else { pos = ind; } } }) }) return spanArr }