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

Javascript/jQuery replace every first text to specific text in string after comma

How to replace every first text with +62 every after comma in string.

Example string:

var phonelist = "0812123456, 081278910, 08221177829";

So the result should be like this:

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

"+62812123456, +6281278910, +628221177829"

>Solution :

Split the phonelist by ,. Then, Update each number by replacing 0 with +62.

const phonelist = "0812123456, 081278910, 08221177829";
const updatedPhoneList = phonelist.split(", ").map( v => v.replace("0", "+62"));

console.log(updatedPhoneList)

// Convert back to string
console.log( updatedPhoneList.join(", "))
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