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

249
Vistas
Javascript: ¿Por qué mi método every () devuelve falso cuando todos los valores de la matriz parecen cumplir con los criterios de los métodos?

Estoy tratando de entender por qué cada método que estoy usando devuelve un valor booleano falso. Aquí está mi código:

 let box1 = document.querySelector(`.box1`); let box2 = document.querySelector(`.box2`); let box3 = document.querySelector(`.box3`); let array = [box1.value, box2.value, box3.value]; box1.value = `X`; box2.value = `X`; box3.value = `X`; array.every((el) => el === `X`)); // This returns false

¿Hay algo que estoy malinterpretando sobre el método every()? Parece que los valores de cada elemento de la matriz satisfacen la condición establecida por el método every(), entonces, ¿por qué devuelve falso?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Porque está cambiando box.value DESPUÉS de haberlo insertado en la matriz.

 let box1 = { value: 1 }; let box2 = { value: 2 }; let box3 = { value: 3 }; // since `value` points to a primitive // that primitive is copied into this array // so box1.value and array[0] are both pointing // to an integer 1 but it's not the same integer! // the value is the same but the location in memory is not let array = [box1.value, box2.value, box3.value]; // this will only change the boxes // but won't affect the `array` box1.value = `X`; box2.value = `X`; box3.value = `X`; // since the array contains a copy of each value // from the box, the changes above only affect // the boxes but not the array itself console.log(array); // 1, 2, 3

about 4 years ago · Juan Pablo Isaza 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