I have an array of objects like this:
[
{
importantKey: 'x',
foo: 'bar',
...
},
{
importantKey: 'y',
foo: 'bar',
...
},
{
importantKey: 'z',
foo: 'bar',
...
},
{
importantKey: 'x',
foo: 'bar',
...
},
{
importantKey: 'y',
foo: 'bar',
...
},
{
importantKey: 'z',
foo: 'bar',
...
},
...
]
And another array that has the values of importantKey:
keysArray = [x, y, z]
How would I get an array with values that are counts of all the objects that have each importantKey in the same order as keysArray? So the final result would be:
[ numberOfObjectsWithKeyX, numberOfObjectsWithKeyY, numberOfObjectsWithKeyZ ]
For this example, the result would be:
[2, 2, 2]
Also keysArray is dynamically generated, so x, y, and z cannot be hard-coded.
map