0

I have a string.

var myexample="'product1','product61','product27','product15'";

I want to then replace product1 with blank

so I say: myexample=myexample.replace(product1, "");

This works, the problem is that is replaces product1 and the product 1 in product15 so my result is:

"'','product61','product27','5'";

I think what I need to do is get the length of the foun object to replace, if it is the same length as my search string then replace else ignore.

any advice welcome as always.

Thanks,

1 Answer 1

1

Just try with:

myexample = myexample.replace("'product1'", "''");

Output:

"'','product61','product27','product15'"
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.