_lodash group objects by itemColor, itemSize, shopId

Viewed 31

I'm using _lodash library, this is my data with objects:

[ {
    "itemColor": "red",
    "itemSize": "L",
    "itemCount": 1,
    "shopId": "shop 1",
    "itemName": "product name 1",
  },
 {
    "itemColor": "red",
    "itemSize": "L",
    "itemCount": 3,
    "shopId": "shop 2",
    "itemName": "product name 1",
  },
  {
    "itemColor": "red",
    "itemSize": "L",
    "itemCount": 5,
    "shopId": "shop 3",
    "itemName": "product name 1",
  },
  {
    "itemColor": "green",
    "itemSize": "S",
    "itemCount": 1,
    "shopId": "shop 3",
    "itemName": "product name 2",
  }]

I need to group items by itemSize, itemColor and as result I need to have this table:

+----------------+-------+------+--------+--------+--------+
| itemName       | color | size | shop 1 | shop 2 | shop 3 |
+================+=======+======+========+========+========+
| product name 1 | red   | L    | 1      | 3      | 5      |
+----------------+-------+------+--------+--------+--------+
| product name 2 | green | S    | 0      | 0      | 1      |
+----------------+-------+------+--------+--------+--------+

If shop are no matches then I need to set 0 value.

0 Answers
Related