0
I have an object in the following format:
[
  {
    "path": "caminho1",
    "subpath": [ { "path": "1" }, { "path": "2" }, { "path": "3" }, { "path": "4" } ]
  },{
    "path": "caminho2",
    "subpath": []
  },{
    "path": "caminho3",
    "subpath": [ { "path": "1" }, { "path": "2" } ]
  },{
    "path": "caminho4",
    "subpath": [ { "path": "1" }, { "path": "2" }, { "path": "3" } ]
  }
]
and I want to turn to the following format:
[
  { params: { path: ["caminho1", "1"] } },
  { params: { path: ["caminho1", "2"] } },
  { params: { path: ["caminho1", "3"] } },
  { params: { path: ["caminho1", "4"] } },
  { params: { path: ["caminho3", "1"] } },
  { params: { path: ["caminho3", "2"] } },
  { params: { path: ["caminho4", "1"] } },
  { params: { path: ["caminho4", "2"] } },
  { params: { path: ["caminho4", "3"] } }
]
How do I make this change with Javascript? I know the function .reduce() can do this, but I can’t understand her right.
Thanks, son, I get it. I should correct myself in relation to reduce pq in this case of a path within a subpath I can’t make it appear the same, or it only appears as a string like "way1,1,way1,2..." or just as an array [Object Object]
– Hennan Lewis