1

I need to replace a dynamic value of a string:

My dynamic value is resulOffset=25

I tried like this:

var str = 'http://example.com?resultLimit=25&resulOffset=25';

var resultOffset = 50;

var newOffset = str.replace(/(resultOffset=)([0-9]+)/, '$1' + resultOffset);    

console.log(newOffset);

but doesn't work. How can I solve it?

0

2 Answers 2

3

here: var str = 'http://example.com?resultLimit=25&resulOffset=25';

you have resulOffset instead of resultOffset.

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

Comments

3

try this one,

var str = 'http://example.com?resultLimit=25&resulOffset={0}';

var resultOffset = 50;

 var newOffset = str.replace('{0}',resultOffset);

 console.log(newOffset);

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.