Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda