title: For to mount json
body: <p>I have in variable <code>bookUnitIdInformacoes</code> this array of objects:</p>
  
  <pre><code>[
    {
      "id": 5,
      "book_id": 33,
      "unit": 1,
      "sequence": 1,
      "description": "UNIT_01_GRAMMAR",
      "qt_question": 5,
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-27 08:11:21",
      "updated_at": "2019-12-30 14:54:12",
      "miniature": null
    },
    {
      "id": 6,
      "book_id": 33,
      "unit": 1,
      "sequence": 2,
      "description": "UNIT_01_VOCABULARY",
      "qt_question": 5,
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-27 08:11:39",
      "updated_at": "2019-12-27 08:11:39",
      "miniature": null
    },
    {
      "id": 7,
      "book_id": 33,
      "unit": 2,
      "sequence": 1,
      "description": "UNIT_02_GRAMMAR",
      "qt_question": 5,
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-27 08:11:46",
      "updated_at": "2019-12-27 08:11:46",
      "miniature": null
    },
    {
      "id": 8,
      "book_id": 39,
      "unit": 1,
      "sequence": 1,
      "description": "UNIT_01_GRAMMAR",
      "qt_question": 5,
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-30 11:07:09",
      "updated_at": "2019-12-30 15:03:50",
      "miniature": null
    }
  ]
  </code></pre>
  
  <p>I have in the variable <code>idioma</code> this array of objects:</p>
  
  <pre><code>[
    {
      "id": 13,
      "code": "ING-NOT-2019",
      "description": "Inglês Noturno 2019",
      "start_date": "2019-12-30T03:00:00.000Z",
      "end_date": "2019-12-31T03:00:00.000Z",
      "period": "Noturno",
      "language": "Inglês",
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-30 10:04:47",
      "updated_at": "2020-01-05 16:08:00",
      "language_substring": "US"
    },
    {
      "id": 14,
      "code": "ESP-MAN-2019",
      "description": "Espanhol manhã 2019",
      "start_date": "2019-12-30T03:00:00.000Z",
      "end_date": "2019-12-31T03:00:00.000Z",
      "period": "Manhã",
      "language": "Espanhol",
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-30 11:06:44",
      "updated_at": "2019-12-30 11:06:44",
      "language_substring": null
    }
  ]
  </code></pre>
  
  <p>I need to create a for() that while the column <code>book_id</code> is equal the index+1, insert in idioma[i].quiz the value of the <code>bookUnitIdInformacoes[i]</code> and when the book_id of the <code>bookUnitIdInformacoes</code> array is different, put in the next position of <code>idioma[i]quiz</code>, so i need this json:</p>
  
  <pre><code>[
    {
      "id": 13,
      "code": "ING-NOT-2019",
      "description": "Inglês Noturno 2019",
      "start_date": "2019-12-30T03:00:00.000Z",
      "end_date": "2019-12-31T03:00:00.000Z",
      "period": "Noturno",
      "language": "Inglês",
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-30 10:04:47",
      "updated_at": "2020-01-05 16:08:00",
      "language_substring": "US",
      "quiz": [
        {
          "id": 5,
          "book_id": 33,
          "unit": 1,
          "sequence": 1,
          "description": "UNIT_01_GRAMMAR",
          "qt_question": 5,
          "status": false,
          "user_id": 1,
          "created_at": "2019-12-27 08:11:21",
          "updated_at": "2019-12-30 14:54:12",
          "miniature": null
        },
        {
          "id": 6,
          "book_id": 33,
          "unit": 1,
          "sequence": 2,
          "description": "UNIT_01_VOCABULARY",
          "qt_question": 5,
          "status": false,
          "user_id": 1,
          "created_at": "2019-12-27 08:11:39",
          "updated_at": "2019-12-27 08:11:39",
          "miniature": null
        },
        {
          "id": 7,
          "book_id": 33,
          "unit": 2,
          "sequence": 1,
          "description": "UNIT_02_GRAMMAR",
          "qt_question": 5,
          "status": false,
          "user_id": 1,
          "created_at": "2019-12-27 08:11:46",
          "updated_at": "2019-12-27 08:11:46",
          "miniature": null
        }
      ]
    },
    {
      "id": 14,
      "code": "ESP-MAN-2019",
      "description": "Espanhol manhã 2019",
      "start_date": "2019-12-30T03:00:00.000Z",
      "end_date": "2019-12-31T03:00:00.000Z",
      "period": "Manhã",
      "language": "Espanhol",
      "status": false,
      "user_id": 1,
      "created_at": "2019-12-30 11:06:44",
      "updated_at": "2019-12-30 11:06:44",
      "language_substring": null,
      "quiz": [
        {
          "id": 8,
          "book_id": 39,
          "unit": 1,
          "sequence": 1,
          "description": "UNIT_01_GRAMMAR",
          "qt_question": 5,
          "status": false,
          "user_id": 1,
          "created_at": "2019-12-30 11:07:09",
          "updated_at": "2019-12-30 15:03:50",
          "miniature": null
        }
      ]
    }
  ]
  </code></pre>
  
  <p>I try something like:</p>
  
  <pre><code>  for(let i=0;i&lt;quizAbertos.length;i++){
          if(i+1 === quizAbertos.length){
              break;
          }else{
      if(bookUnitIdInformacoes[i].book_id === bookUnitIdInformacoes[i+1].book_id){
          idioma[i].quiz = bookUnitIdInformacoes[i]
      }
    }
  </code></pre>
  
  <p>But i'm getting wrong json..</p>
  
  <p>@Edit:</p>
  
  <p>Actually i'm trying something like:</p>
  
  <pre><code> let book_id
    let i_book_id = 0
    let i_mudou_book_id = 0;
  
    for(let i=0;i&lt;bookUnitIdInformacoes.length;i++){
     if(bookUnitIdInformacoes[i+1] === undefined){
      book_id = bookUnitIdInformacoes[bookUnitIdInformacoes.length-1].book_id
     }else{
      if(bookUnitIdInformacoes[i].book_id === bookUnitIdInformacoes[i+1].book_id){
       i_mudou_book_id++
      }
     }
    }
  
  
     idioma[0].quiz = bookUnitIdInformacoes.splice(0,i_mudou_book_id+1)
     idioma[1].quiz = bookUnitIdInformacoes
  </code></pre>
  
  <p>but this way if i have more than 2 length i will be have problems and if i have only one length i will be too have problems.</p>