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

283
Vistas
How to delete the second word using : as separator on java script

so i have string like this

accept : menerima 
accuse : menuduh 
achieve : mencapai 
acquire : memperoleh 
adapt : menyesuaikan 
add : menambahkan 

and how to delete the second word using : as separator, And make the result like this.

accept 
accuse 
achieve 
acquire
adapt 
add 

thanks

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

A regex will work.

const rx = /\s+:.*$/mg
str.replace(rx, '')

https://regex101.com/r/sV2TnQ/1

The g flag will replace multiple occurances. The m flag lets $ match end of line or document.

So 'spaces', a 'colon', and 'all to end of line'

about 4 years ago · Juan Pablo Isaza Denunciar

0

try like this,

const str = 'accept : menerima'

console.log(str.slice(0,str.indexOf(":")))

You can create one method, which will take string as input and will return new string.

const txt = 'accept : menerima'

function getCroppedString(str){
    return str.slice(0,str.indexOf(":"));
}

getCroppedString(txt)

console.log(getCroppedString(txt));

const str = 'accept : menerima'

console.log(str.slice(0,str.indexOf(":")))

about 4 years ago · Juan Pablo Isaza Denunciar

0

A different approach to a regex would be to loop over the lines, and split the : using a map.

const string = `accept : menerima
accuse : menuduh 
achieve : mencapai 
acquire : memperoleh 
adapt : menyesuaikan 
add : menambahkan`;

const lines = string.split("\n")
.map((line) => line.split(" : ")[0])

// Optionally if you would like to return the output as a single string
.join("\n"); 

console.log(lines);

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