你好,我想根據(jù)數(shù)組中唯一的項(xiàng)合并一個(gè)數(shù)組。我擁有的對(duì)象totalCells = []在這個(gè)Cells數(shù)組中,我有幾個(gè)像這樣的對(duì)象totalCells = [
{
cellwidth: 15.552999999999999,
lineNumber: 1
},
{
cellwidth: 14,
lineNumber: 2
},
{
cellwidth: 14.552999999999999,
lineNumber: 2
},
{
cellwidth: 14,
lineNumber: 1
}];現(xiàn)在,我想要?jiǎng)?chuàng)建一個(gè)數(shù)組,其中我有基于lineNumber的數(shù)組組合。就像我有一個(gè)帶有l(wèi)ineNumber屬性和cellWidth集合的對(duì)象一樣。我能做這個(gè)嗎?我可以循環(huán)遍歷每一行,檢查行號(hào)是否相同,然后推送單元格寬度。我能想出什么辦法嗎?我想得到這樣的輸出。totalCells = [{
lineNumber : 1,
cells : [15,16,14]},{
lineNumber : 2,
cells : [17,18,14]}]
如何在javascript中組合數(shù)組
慕桂英3389331
2019-07-13 16:15:38