How to parse an array of arrays correctly?

  • 0
    Hello everyone !!!
    Help please, I'm new to this field)
    there is such a structure that comes:
    [
      [ {id: 1}, {id: 2}, {id: 3} ],
      [ {id: 1}, {id: 2}, {id: 3} ],
      [ {id: 1}, {id: 2}, {id: 3} ]
    ]


    I receive such data and I need to turn it into one array of objects, that is, combine all the arrays and change each id (by adding an index) to get something like the following array

    [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}, {id: 7}, {id: 8}]


    maybe using map, then reduce?

    they come to the function as list
    renderLists = (list) => {
      return list.map(item => {
         и вот тут не знаю )
      }
    }
    JavaScript Anonymous, May 16, 2019

  • 1 Answers
  • 0
    arr.flat (). map ((n, i) = & gt; ({... n, id: i + 1}))
    Scarlett Francis

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!