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

192
Views
Remove second part of string with split()

I have a variable with a string, let's say this one, which I then display on a page on the site:

let value = "qwe asd — bensound summer";

document.getElementById("text").innerHTML = value;

And I want to remove its second part when displaying this line on the page bensound summer along with a dash —.

And in order to receive only the first part, which is before the dash, when displayed on the page, in the form: qwe asd.

I read about str.split() but didn't find anything like it and didn't quite understand how it all works.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Use the split method

let value = "qwe asd - bensound summer";

value = value.split('-')[0] // 

document.getElementById("text").innerHTML = value;
about 4 years ago · Santiago Trujillo Report

0

You can use it like this:

let value = "qwe asd — bensound summer";
let splittedString = value.split("-");

document.getElementById("text").innerHTML = splittedString[0];

Hope, it helps!!

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