I have this function:
async geraQuiz(idEstudante) {
let idioma = new Array()
let livrosUnidadesGerarQuiz = new Array()
const idsClassesEstudante = await this.getIdClassesEstudante(idEstudante) // Here i have this array return: [2,3]
for(let i=0;i<idsClassesEstudante.length;i++){
livrosUnidadesGerarQuiz = new Array() // Clear the array
idioma.push(await this.getDadosClasseIdiomaEstudante(idsClassesEstudante[i]))
livrosUnidadesGerarQuiz = await this.getLivrosUnidadesGerarQuiz(idsClassesEstudante[i], idBookClasseEstudante[0], qtdQuizGerar)
idioma[i].quiz = livrosUnidadesGerarQuiz
console.log(JSON.stringify(idioma))
console.log(idioma[i].quiz[0])
...
In the console.log(idioma)
i have this array of objects:
[
{
"id": 2,
"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": 1,
"class_id": 2,
"book_unit_id": 1,
"book_id": 1,
"start_date": "2020-01-03T03:00:00.000Z",
"end_date": "2020-01-15T03:00:00.000Z",
"book_unit_sequence": 1,
"status": false,
"user_id": 1,
"created_at": "2019-12-27T11:11:21.000Z",
"updated_at": "2019-12-30T17:54:12.000Z",
"unit": 1,
"sequence": 1,
"description": "UNIT_01_GRAMMAR",
"qt_question": 5,
"miniature": null
},
{
"id": 2,
"class_id": 2,
"book_unit_id": 2,
"book_id": 1,
"start_date": "2020-01-15T03:00:00.000Z",
"end_date": "2020-01-31T03:00:00.000Z",
"book_unit_sequence": 2,
"status": false,
"user_id": 1,
"created_at": "2019-12-27T11:11:39.000Z",
"updated_at": "2019-12-27T11:11:39.000Z",
"unit": 1,
"sequence": 2,
"description": "UNIT_01_VOCABULARY",
"qt_question": 5,
"miniature": null
},
{
"id": 3,
"class_id": 2,
"book_unit_id": 3,
"book_id": 1,
"start_date": "2020-01-31T03:00:00.000Z",
"end_date": null,
"book_unit_sequence": 1,
"status": false,
"user_id": 1,
"created_at": "2019-12-27T11:11:46.000Z",
"updated_at": "2019-12-27T11:11:46.000Z",
"unit": 2,
"sequence": 1,
"description": "UNIT_02_GRAMMAR",
"qt_question": 5,
"miniature": null
}
]
}
]
But when i try to acess the property with: console.log(idioma[i].quiz[0]
i receive undefined
, but the console.log()
shows that i have this property quiz
and is not undefined
, why this is happening?
I put a return after the console.log(idioma[i].quiz[0])
to prevent that is not subscribing but i have the same result; and
I put one console.log(i)
and i have the value 0
@Edit
the console.log(idioma)
without stringify:
[
Class {
__setters__: [
'$attributes',
'$persisted',
'primaryKeyValue',
'$originalAttributes',
'$relations',
'$sideLoaded',
'$parent',
'$frozen',
'$visible',
'$hidden'
],
'$attributes': {
id: 2,
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-30T13:04:47.000Z,
updated_at: 2020-01-05T19:08:00.000Z,
language_substring: 'US',
quiz: [Array]
},
'$persisted': true,
'$originalAttributes': {
id: 2,
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-30T13:04:47.000Z,
updated_at: 2020-01-05T19:08:00.000Z,
language_substring: 'US'
},
'$relations': {},
'$sideLoaded': {},
'$parent': null,
'$frozen': false,
'$visible': undefined,
'$hidden': undefined
}
]