1

This is string

chat('star_comment','11211967','17','HF00008','MLR51101639100ICI100','B19','0','2020'); 

i want to replace it to like this in javascript:

chat('star_comment','11211967','17','HF00008','MLR51101639100ICI100','B19','RO_RX','2020'); 

my code is like this:

var str = "chat('star_comment','11211967','17','HF00008','MLR51101639100ICI100','B19','0','2020')";
check = "0";
var res = str.replace("/\/"+check+"\//", "RO_RX"); 

but this is not working

3
  • 1
    str.replace("'0'", "'RO_RX'") Why not this? Commented May 16, 2021 at 20:40
  • Where is the single quotes around 0 in check variable? Commented May 16, 2021 at 20:40
  • i want to add "/" in both side. i need to like this Commented May 16, 2021 at 20:41

1 Answer 1

1

Simplify the replacement and put the single quotes in the selector (check) direcctly

var str = "chat('star_comment','11211967','17','HF00008','MLR51101639100ICI100','B19','0','2020')";
let check = "'0'";
var res = str.replace(check, "'RO_RX'"); 
console.log(res);

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.