Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading