Hola colegas tengo una gran pregunta, espero puedan ayudarme 😅
tengo estos datos
const datos =
{ cod_leccionario: 25496,
iso: 'C4 FOR. 1.3',
curso: 'SEXTO AÑO DE EDUCACIÓN BÁSICA MEDIA',
paralelo: 'A ',
fecha: '07/08/2018',
hora: 8,
materia: 'LANGUAGE ARTS',
destrezas: 'EFL 3.2.8 Spell out key vocabulary items using the English alphabet. (Example: names, colors, animals, possessions, etc.) (spelling vocabulary from the lesson 7, and 8)',
tareas: '',
observaciones: '',
profesor: 'ZAMBRANO VERONICA',
firma: 'No esta firmado',
observaciones_coordinador: '',
observaciones_inspector: '' },
{ cod_leccionario: 25498,
iso: 'C4 FOR. 1.3',
curso: 'SEXTO AÑO DE EDUCACIÓN BÁSICA MEDIA',
paralelo: 'A ',
fecha: '07/08/2018',
hora: 9,
materia: 'LANGUAGE ARTS',
destrezas: 'EFL 3.2.8 Spell out key vocabulary items using the English alphabet. (Example: names, colors, animals, possessions, etc.) (spelling vocabulary from the lesson 7, and 8)',
tareas: '',
observaciones: '',
profesor: 'ZAMBRANO VERONICA',
firma: 'No esta firmado',
observaciones_coordinador: '',
observaciones_inspector: '' },
{ cod_leccionario: 25502,
iso: 'C4 FOR. 1.3',
curso: 'SEXTO AÑO DE EDUCACIÓN BÁSICA MEDIA',
paralelo: 'A ',
fecha: '08/08/2018',
hora: 1,
materia: 'LANGUAGE ARTS',
destrezas: 'EFL 3.3.9 Identify and use reading strategies to make text more comprehensible and meaningful. (Example: skimming, scanning, previewing, predicting, reading to identify causes and effects)\nEFL 3.3.8 Make and support inferences from evidence in a text with reference to features of written English. (Example: vocabulary, facts that help understand conclusions.) \n',
tareas: '',
observaciones: '',
profesor: 'ZAMBRANO VERONICA',
firma: 'No esta firmado',
observaciones_coordinador: '',
observaciones_inspector: '' },
{ cod_leccionario: 25507,
iso: 'C4 FOR. 1.3',
curso: 'SEXTO AÑO DE EDUCACIÓN BÁSICA MEDIA',
paralelo: 'A ',
fecha: '08/08/2018',
hora: 2,
materia: 'LANGUAGE ARTS',
destrezas: 'EFL 3.3.9 Identify and use reading strategies to make text more comprehensible and meaningful. (Example: skimming, scanning, previewing, predicting, reading to identify causes and effects)\nEFL 3.3.8 Make and support inferences from evidence in a text with reference to features of written English. (Example: vocabulary, facts that help understand conclusions.) \n',
tareas: '',
observaciones: '',
profesor: 'ZAMBRANO VERONICA',
firma: 'No esta firmado',
observaciones_coordinador: '',
observaciones_inspector: '' },
{ cod_leccionario: 25901,
iso: 'C4 FOR. 1.3',
curso: 'SEXTO AÑO DE EDUCACIÓN BÁSICA MEDIA',
paralelo: 'A ',
fecha: '14/08/2018',
hora: 7,
materia: 'LANGUAGE ARTS',
destrezas: 'EFL 3.2.8 Spell out key vocabulary items using the English alphabet. (Example: names, colors, animals, possessions, etc.) (spelling vocabulary from the lesson 7, and 8)',
tareas: '',
observaciones: '',
profesor: 'ZAMBRANO VERONICA',
firma: 'No esta firmado',
observaciones_coordinador: '',
observaciones_inspector: '' },
{ cod_leccionario: 25904,
iso: 'C4 FOR. 1.3',
curso: 'SEXTO AÑO DE EDUCACIÓN BÁSICA MEDIA',
paralelo: 'A ',
fecha: '14/08/2018',
hora: 8,
materia: 'LANGUAGE ARTS',
destrezas: 'EFL 3.2.8 Spell out key vocabulary items using the English alphabet. (Example: names, colors, animals, possessions, etc.) (spelling vocabulary from the lesson 7, and 8)',
tareas: '',
observaciones: '',
profesor: 'ZAMBRANO VERONICA',
firma: 'No esta firmado',
observaciones_coordinador: '',
observaciones_inspector: '' }
Tengo un arreglo al que intento ingresarles estos objetos en las distintas posiciones del arreglo agrupados por la fecha, los que tienes fecha '07/08/2018'
que vayan en la posición 0, lo que tienen fecha '08/08/2018'
que vayan en la posición 1 y así consecutivamente, para ello cree estas lineas de codigo:
let data = [];
data.push({registros:[]});
let k = 0;
let j = 0;
for (let i = 0; i < datos.length; i++) {
if (datos[i].fecha == datos[j].fecha) {
data[k].registros.push(datos[i]);
j = i;
} else {
k++;
data[k].registros.push(datos[i]);
j = i;
}
}
console.log(data);
pero al ejecularlo tengo el siguiente error
TypeError: Cannot read property 'registros' of undefined
probe cambiando data[k]
quemandole la posición data[0]
(para realizar pruebas) y ahí si ingresa los datos, solo que todos van en la misma posición y no es lo que deseo, tambien intente poner data[data.length-1]
en el if
y data[data.length]
en el else
, pero obtengo el mismo error TypeError: Cannot read property 'registros' of undefined
registros
a la primera posición, en las demás no existe y por eso te dice que no esta definido.const datos = [{obj1 : 1},{obj1 : 2}....]