I have an array that looks like this :
[
{ id: 9,
email: '[email protected]',
product: 'handbag',
date: 2019-03-11 },
{ id: 10,
email: '[email protected]',
product: 'handbag',
date: 2019-03-11 },
{ id: 11,
email: '[email protected]',
product: 'handbag',
date: 2019-03-11 },
{ id: 12,
email: '[email protected]',
product: 'handbag',
date: 2019-03-11 },
{ id: 13,
email: '[email protected]',
product: 'joystick',
date: 2019-03-11 },
etc...............
]
NOTE keys of objects in array are static, but values are dynamic except for email => the email is static
NOTE2 the length of array are dynamic not static, so the number of objects are dynamic
how to filter this array to get the result like this
{
email: '[email protected]', // email here is static AKA is known
handbag: 4, // keys here , not just keys they are the values of keys in objects in array , and i want to use them like has access to them
smartphone: 1,
joystick: 1,
etc.......
}
So the final line of out put to the client to be something like this:
You have 4 products of handbag and 1 product of joystick and 1 product of smartphone etc.................
NOTE I don't know the length of the last object , and i don't know the length of array, all data are dynamic except for email.
This question, I think it's a little bit of challenge.