I have this object, and I would like to know how many items there are for each user and add them to a new object (users are dynamic)
[{
"user": "user1"
}, {
"user": "user1"
}, {
"user": "user2"
}, {
"user": "user3"
}]
For example, with the previous object you should create a new one like this:
[{"user":"user1", "count": 2},{"user":"user2","count":1},{"user":"user3","count":1}]
I had tried a filter, doing something like this
const count = (array, user) => {
return array.filter(n => n.user=== user).length;
};
But the new object was created by harcode
I would very much appreciate your help