Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!