【发布时间】:2019-01-20 09:12:08
【问题描述】:
我有一个矩阵响应数组:
matrixArray = [
{Responded: 1, RowName: row1, ColName: col1},
{Responded: 2, RowName: row1, ColName: col2},
{Responded: 0, RowName: row1, ColName: col3},
{Responded: 0, RowName: row2, ColName: col1},
{Responded: 0, RowName: row2, ColName: col2},
{Responded: 1, RowName: row2, ColName: col3},
{Responded: 1, RowName: row3, ColName: col1},
{Responded: 0, RowName: row3, ColName: col2},
{Responded: 1, RowName: row3, ColName: col3},
...
...
];
它告诉某列已经响应了多少次一行。 我需要以下格式的对象数组:
matrixArray = [
{
RowName: row1,
col1: 1, //Here '1' is no. of times column responded
col2: 2,
col3: 0
},
{
RowName: row2,
col1: 0,
col2: 0,
col3: 1
},
{
RowName: row3,
col1: 1,
col2: 0,
col3: 1
},
];
我为此使用 TypeScript。 谢谢。
【问题讨论】:
-
请分享您的尝试。
-
您可以编辑您的问题。另外,正如我上面所说,你应该在人们帮助你之前展示你尝试过的东西。至少分享一下你的方法是什么,以及你想不通的地方。
-
我已经准备好了答案,无论如何我都会在我忘记它之前发布它。下次请努力展示你的尝试。
-
道歉@Jeto,但有一些连接问题,所以无法发布我的尝试。我在数组上使用了 forEach 和 .filter 。我的计划是首先在不同的数组中获取行,然后将相应的列推送到它。但这个计划实际上并没有奏效。
标签: javascript arrays typescript object