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

131
Vistas
javascript expression to check if array includes only a specified type

Hello everyone I struggling to create an expression to check if a specific array includes only a specified type values.Here is what I tried :

const isArrayOfType = (arr, type) =>
  arr.forEach((item) => typeof item == type) ? true : false;

const arr = [1, 2, 3];
const typ = 'number';

console.log(isArrayOfType(arr, typ));

The main goal is to not use return in the expression.

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

0

forEach doesnt return anything, I think you're looking for every (and the ternary operator is unecessary as it already returns a boolean)

const isArrayOfType = (arr, type) =>
  arr.every((item) => typeof item == type);

const arr = [1, 2, 3];
const typ = 'number';

console.log(isArrayOfType(arr, typ));
console.log(isArrayOfType(["one",2,3], typ));

about 4 years ago · Santiago Gelvez 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