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

152
Vistas
How to remove everything that occurs after the last occurrence of a character in JavaScript?

For example, I have a string

"A - B - C asdas K - A,B,C"

Let the character be "-"

I want to save everything before the last occurrence of "-" so "A - B - C asdas K " should be saved.

I have tried this:

str = str.split(":").pop();

How can I do this?

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

0

You can do something like this:

var str = "A - B - C asdas K - A,B,C";
console.log(str.substring(0, str.lastIndexOf("-")));

Firstly, you get the last index of the char that interest you: '-', then you are using substring which get 0-X string.

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