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

76
Vistas
Array.some() function did not matched for undefined
var array = [3,4,5];
delete array[1];
console.log(array);
console.log(array[1]);
array.some(element => {
    console.log(element);
    return element === 3
})
array.some(element => {
    console.log(element);
    return element === undefined
})

PS: In the image below array for above code is taken as a and element is taken as b

enter image description here

Why does Array.some() function did not matched for undefined at index 1? Does it handles undefined differently?

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

0

The .some doesn't check the empty index The undefined must be statically written

const myArr = [1,,3];
console.log(myArr)

myArr.some(elem => console.log(elem))

 myArr[1] = undefined;
console.log(myArr)

myArr.some(elem => console.log(elem))

If you want to detect empty indices

this should work

const myArr = [1,,3];


function hadEmptyIndex(arr){
  
  for(const member of arr){
    if(typeof member === "undefined") return true
  }
  
  return false
}


console.log(hadEmptyIndex(myArr))

about 4 years ago · Santiago Trujillo Denunciar

0

That's because you are not iterating over empty values, so you can't really check if the value is equal to undefined or not.

Once you delete an item from an array, the array methods such as some, forEach, and etc will skip the item in the iteration.

What you can do instead is setting the element to null, then it's gonna be iterable:

var a = [1, 2, 3];
a[0] = null // [ null, 2, 3 ]
a.some(b => b === null) // true
about 4 years ago · Santiago Trujillo Denunciar

0

Great question, array.some() function only iterate over indexes with assign values,

callbackFn is invoked only for indexes of the array with assigned values. It is not invoked for indexes which have been deleted or which have never been assigned values.

for further reading Read Here

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