Counts the occurrences of each distinct value of key across the array. Items where the key value is not a valid property key are skipped.
key
The array to count.
The key whose values are used as group identifiers.
countBy( [{ role: "admin" }, { role: "user" }, { role: "admin" }], "role")// => { admin: 2, user: 1 } Copy
countBy( [{ role: "admin" }, { role: "user" }, { role: "admin" }], "role")// => { admin: 2, user: 1 }
Counts the occurrences of each distinct value of
keyacross the array. Items where the key value is not a valid property key are skipped.