从数组中过滤数据并将其分组到javascript中?

时间:2018-02-21 20:46:22

标签: javascript jquery reactjs typescript sharepoint

我有一个如下所示的数组

OStatus=["hold","approved","rejected","hold","approved","rejected","hold","approved"]

我在结果中想要这样的东西

Oinfo=["hold":3,"approved":3,"rejected":2].

1 个答案:

答案 0 :(得分:1)

假设您想生成一个对象,该对象将来自输入数组的元素的键映射到每个元素的计数值,您可以使用Array.reduce,如下所示:

import { Cell } from './modules/Cell';