您好,我想根据数组中的唯一项合并一个数组。
我拥有的对象
totalCells = []
在这个 totalCells 数组中,我有几个这样的对象
totalCells = [
  {
    cellwidth: 15.552999999999999,
    lineNumber: 1
  }, 
  {
    cellwidth: 14,
    lineNumber: 2
  },
  {
    cellwidth: 14.552999999999999,
    lineNumber: 2
  }, 
  {
    cellwidth: 14,
    lineNumber: 1
  }
];
现在我想创建一个数组,其中我有基于 lineNumber 的数组组合。
就像我有一个带有 lineNumber 属性和 cellWidth 集合的对象。我可以这样做吗?
我可以遍历每一行并检查行号是否相同,然后推送该单元格宽度。有什么办法让我想出来吗?
我正在尝试获得这样的输出。
totalCells = [
{
  lineNumber : 1,
  cells : [15,16,14]
},
{
  lineNumber : 2,
  cells : [17,18,14]
}
]