How to combine an array in javascript

var newCells = [];
for (var i = 0; i < totalCells.length; i++) {
    var lineNumber = totalCells[i].lineNumber;
    if (!newCells[lineNumber]) { // Add new object to result
        newCells[lineNumber] = {
            lineNumber: lineNumber,
            cellWidth: []
        };
    }
    // Add this cellWidth to object
    newcells[lineNumber].cellWidth.push(totalCells[i].cellWidth);
}

What about something like this :

totalCells.reduce(function(a, b) {
  if(!a[b.lineNumber]){
    a[b.lineNumber] = {
      lineNumber: b.lineNumber,
      cells: [b.cellwidth]
    }
  }
  else{
    a[b.lineNumber].cells.push(b.cellwidth);
  }
  return a;
}, []);

Hope this helps!