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

177
Vistas
Check the end of string (regular expression)

i am trying to heck if a string (first argument, str) ends with the given target string (second argument, target). function confirmEnding(str, target) { return /target$/.test(str) } Test stringconfirmEnding("Bastian","n") show false. What i am doing wrong? Can i use regular expression as argument of function? ;

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

0

If it's always a string, then you can just use String#endsWith

function checkEnd(str, target) {
  return str.endsWith(target);
}

console.log(checkEnd("Bastion", "n"));

If you want to cast target into a regex, but note that this won't escape out any of the special characters in target. i.e. checkEnd('special)',')') will fail due to the regex being invalid:

function checkEnd(str, target) {
  return new RegExp(`${target}$`).test(str);
}

console.log(checkEnd("Bastion", "n"));

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