我有一个如下所示的数组
OStatus=["hold","approved","rejected","hold","approved","rejected","hold","approved"]
我在结果中想要这样的东西
Oinfo=["hold":3,"approved":3,"rejected":2].
答案 0 :(得分:1)
假设您想生成一个对象,该对象将来自输入数组的元素的键映射到每个元素的计数值,您可以使用Array.reduce,如下所示:
import { Cell } from './modules/Cell';