Skip to content
Advertisement

Why doesn’t this function change the case of the string when it has a similar character like the first letter?

Can’t understand why the following function works for some strings an didn’t work for some which has a similar character like the first.

JavaScript

Advertisement

Answer

The function String.prototype.replace replaces the first occurrence when the first argument is a string.

You can split the string change the index to uppercase and finally join the chars.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement