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

261
Vistas
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 Respuestas
Responde la pregunta

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 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