0

I am calling replace() on a string to change the chars but for some reason it does not change it.

 var result = "Hi!"
 result.replace('i','z')

In logs I still see Hi!

0

1 Answer 1

3

Strings are immutable. When you call replace, the function returns a new String instance. You'll have to assign the result to something if you want to use it elsewhere.

var result = "Hi!"
result = result.replace('i','z')
Sign up to request clarification or add additional context in comments.

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.