30秒学会 JavaScript 片段 – countBy
Groups the elements of an array based on the given function and returns the count of elements in each group.
Use Array.prototype.map()
to map the values of an array to a function or property name.
Use Array.prototype.reduce()
to create an object, where the keys are produced from the mapped results.
继续阅读 30秒学会 JavaScript 片段 – countBy