Estoy tratando de encontrar el índice de un objeto en una matriz.
for (let i = 0; i < sitesDeTir.length; i++) { let affIndex = affectations.findIndex((aff) => aff.id_sdt === sitesDeTir[i].id); if (affIndex === -1) { // action } else { // action } }
Cuando uso el depurador de Chrome, puedo ver que sitesDeTir[i].id es igual a 371 (número). También he escarbado en el arreglo (llamado afectaciones) y veo que hay un objeto que tiene id_sdt a 371 (número) pero siempre recibo -1.
¿Qué me estoy perdiendo aquí? Lo siento por el enlace, no tengo suficiente reputación para insertarlo en la publicación.
El problema ocurre porque comparas manzanas con plátanos :-) Escribe id_SDT
en lugar id_sdt
.
for (let i = 0; i < sitesDeTir.length; i++) { let affIndex = affectations.findIndex((aff) => aff.id_SDT === sitesDeTir[i].id); if (affIndex === -1) { // action } else { // action } }