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

269
Visualizações
Trying to splice several words inside of a string

I'm an absolute beginner with javascript and need someone to hold my hand. I have a string that I am trying to splice several words out of, and need help doing so. It's probably easier if I use an example:

What I have:

"Testing::testing2::testing3 Sample::sample2::sample3"

What I want spliced out:

"testing3 sample3"

The code that I am using right now will only display the last word (sample3), but I need it to show the last word before the 'space' in both sequences. Help?

Current code:

var the_string = "Testing::testing2::testing3 Sample::sample2::sample3";
var parts = the_string.split('::').slice(-1);
document.getElementById('tagslast').innerHTML = parts;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can split the string by a space, then split each individual item by :: and get the last items:

const str = "Testing::testing2::testing3 Sample::sample2::sample3";

const result = str.split(" ").map(e => e.split("::").slice(-1)[0])

console.log(result)

about 4 years ago · Juan Pablo Isaza 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