i have an array like given below
OStatus=["hold","approved","rejected","hold","approved","rejected","hold","approved"]
i want something like this in result
Oinfo=["hold":3,"approved":3,"rejected":2].
i have an array like given below
OStatus=["hold","approved","rejected","hold","approved","rejected","hold","approved"]
i want something like this in result
Oinfo=["hold":3,"approved":3,"rejected":2].
Assuming that you'd like to produce an object which maps keys which are elements from an input array to values which are the counts of each element, you could use Array.reduce, like so:
Oinfo = OStatus.reduce((acc, x) => ({ ...acc, [x]: (acc[x] || 0) + 1 }), {})