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

108
Vistas
filter and regex issue

I want to filter an array with a function.

if (this.pendingItems.customer?.emailAddresses) {
  this.pendingItems.customer.emailAddresses.filter(email => {
    isEmailValid(email);
  });
}

the function isEmailValid()

export function isEmailValid(s: string): boolean {
  const re =
    /^[a-z0-9+-][a-z0-9_+-]*(\.[a-z0-9_+-]+)*@([a-z0-9-]+\.)+[a-z0-9-]{2,}$/i;
  return re.test(s);
}

return the correct response (true or false) with the emails(test@email.com and test2email) I pass it, but the filter don't work.

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

0

You need to modify your expression slightly. The method you pass to the filter function should return true/false but it always returns void (which will be cast to false).

filter(email => isEmailValid(email))
or
filter(isEmailValid)
or
filter(email => { return isEmailValid(email) })

In case you missed it - you forgot to return the result of the isEmailValid ;)

about 4 years ago · Juan Pablo Isaza Denunciar

0

So the solution was:

if (this.pendingItems.customer?.emailAddresses) {
  this.pendingItems.customer.emailAddresses = this.pendingItems.customer.emailAddresses.filter(isEmailValid);
}

I forgot to reassign the variable ;p

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