Search code examples
javascriptlodash

Grouping an object with two attributes for table


i have an api in rest that return the following object :

The object

[
    {
      "attributes": {
        "CodAP" : 1,
        "Period": 1991,
        "People": 6000,
        "Child" : 3000
      }
    },
    {
      "attributes": {
        "CodAP" : 1,  
        "Period": 2000,
        "People": 5000,
        "Child" : 1000
      }
    }
]

Explanation

I need to add these values in the following sequence in the table: enter image description here

Versions

I am using the version of lodash : 4.17.4

Also am using vue.js at the version: 2.3.3

Note: I even asked this question but could not express myself in the best way. Now I think it's clearer what I need. follows my previous post: Grouping an object with two attributes


Solution

  • Maybe you mean this?

    _.groupBy(obj, (v) => v.attributes.CodAP)
    

    https://jsfiddle.net/wk7zL0gr/