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

127
Vistas
How does one perform a logical AND on an array of booleans in javscript?

Scenario and Question

Say you have an array of booleans in javascript:

[true, false, true, true, false]

What's the best practice for performing a logical 'AND' operation on all of these values so that the above example would become:

false

In other words, what's the best practice for AND'ing all of these values together?


My solution

The best/cleanest way I thought of is using the reduce function like so:

const array1 = [true, false, true, true];

const initialValue = array1[0];
const array1And = array1.reduce(
  (previousValue, currentValue) => previousValue && currentValue,
  initialValue
);

console.log(array1And); //false

Is there a simpler way to achieve the same?

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

0

You could use the .every for AND or the .some for OR

const array1 = [true, false, true, true];

const or = array1.some(Boolean);
const and = array1.every(Boolean);

console.log({ or, and });

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