Hello I want to merge a array based on the unique item in the array.
The object that I have
totalCells = []
In this totalCells arr
Do you mean something like this?
var cells = [
{
cellwidth: 15.552999999999999,
lineNumber: 1
},
{
cellwidth: 14,
lineNumber: 2
},
{
cellwidth: 14.552999999999999,
lineNumber: 2
},
{
cellwidth: 14,
lineNumber: 1
}
]
var totalCells = [];
for (var i = 0; i < cells.length; i++) {
var cell = cells[i];
if (!totalCells[cell.lineNumber]) {
// Add object to total cells
totalCells[cell.lineNumber] = {
lineNumber: cell.lineNumber,
cellWidth: []
}
}
// Add cell width to array
totalCells[cell.lineNumber].cellWidth.push(cell.cellwidth);
}