1

Below is my string.When I console b it is showing as below output:

var a='602,315,805,887,810,863,657,665,865,102,624,659,636';
var b = a.replace(',',"$");
console.log(b);

output:

602$315,805,887,810,863,657,665,865,102,624,659,636

What should I do to replace complete commas in string to $.

0

4 Answers 4

5

Use regexp, /,/g with global flag

var a ='602,315,805,887,810,863,657,665,865,102,624,659,636';
var b = a.replace(/,/g,"$");

Example

Sign up to request clarification or add additional context in comments.

Comments

0

This question already has an answer anyway i have provide a different approach

var var a ='602,315,805,887,810,863,657,665,865,102,624,659,636';
var change= '$'
a= a.split(',').join(change);

Comments

0

You can use String methods .split() and .join() to make an array then glue the pieces back together.

var b = a.split(',').join('$');

Comments

0
str.replace(/,/g,"$");

will replace , with $

DEMO

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.