[Javascript] How do I remove a given character from a string?
I want to remove a given character from the string. For example, I want to remove w from Hello world. How to do that in Javascript?
1 Answer
4 years ago by Jahaan
You can use any of the below methods to remove a given character from a string.
Method 1
string.replace('character-to-be-removed','')
Method 2
string.split('character-to-be-removed').join('');
Example:
let str = "Hello World";
console.log(str.replace('W', ''));
console.log(str.split('W').join(''));
4 years ago by Meera