0

I have an object array looking like this:

[
  {
    "number": 1,
    "salary": 2000,
    "premium": 200,
    "taxes": 500,
    "friends": [
      {
        "number": 1,
        "salary": 10,
        "premium": 10,
        "taxes": 50,
        "parents": [
          {
            "number": 1,
            "salary": 4,
            "premium": 10,
            "taxes": 50,
            "cars": [{ "car": 1, "bike": "fast" }]
          },
          {
            "number": 2,
            "salary": 4,
            "premium": 10,
            "taxes": 50,
            "cars": [{ "car": 1, "bike": "fast" }]
          },
        ]
      }
    ]
  }
]

How can I get the arrays out of that object? The main array might contain more objects of that kind in the future. The arrays will always have the same key, e.g. friends, parents etc.

I tried map and flat functions, but I don't really get the result I need.

Would be great if someone could help.

  • 1
    You need to give an example of what you have tried to solve the problem and what the desired output is. – max Mar 19 '19 at 22:36
  • 1
    What is your desired output ? – jo_va Mar 19 '19 at 22:37
  • We need to know the ouput, also it would be useful to know if the number of levels in your array (it's not a object at first) is always the same. If not, you need to create something like a cube object to loop through al the child elements. – Joey Mar 19 '19 at 22:47
  • Have a look at [Access / process (nested) objects, arrays or JSON](https://stackoverflow.com/q/11922383/218196) – Felix Kling Mar 19 '19 at 23:14

0 Answers0