Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
unexpected result when mapping two arrays with undefined values

Why does this map return different results when I apply it on two arrays that are supposed to be perfectly equal to each other?

let a = [1, 2, 3];
a.length = 7;
let b = [1, 2, 3, undefined, undefined, undefined, undefined];
console.log("a: " + a); //a: 1,2,3,,,,
console.log("b: " + b); //b: 1,2,3,,,,
console.log("It is " + a.every((x, i) => x === b[i]) + " that these arrays are perfectly equal."); //It is true that these arrays are perfectly equal.
a = a.map(x => 1);
b = b.map(x => 1);
console.log("a: " + a); //a: 1,1,1,,,,
console.log("b: " + b); //b: 1,1,1,1,1,1,1

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Array a has 4-7 just as empty. In b 4-7 are undefined. After using the map function, that difference is showing up as "1,1,1,,,," and "1,1,1,1,1,1,1"

about 4 years ago · Santiago Trujillo Denunciar

0

These two arrays are not the same. pic

Due to this doc when you change the length of an array javascript injects "empty statement" in new indexes.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda