To remove a specific character from a string in JavaScript, you can use the `replace` method.
In this example,
str
with a value of "Hello World"
.replace
method with a regular expression /l/g
to replace all occurrences of 'l' with an empty string in str
.replace
method returns a new string with the specified characters replaced.str
to the console.let str = "Hello World";
let modifiedStr = str.replace(/l/g, '');
console.log("Modified string: ", modifiedStr);
Modified string: Heo Word
In this example,
str
with a value of "apple"
.replace
method with a regular expression /a/g
to replace all occurrences of 'a' with an empty string in str
.replace
method returns a new string with the specified characters replaced.str
to the console.let str = "apple";
let modifiedStr = str.replace(/a/g, '');
console.log("Modified string: ", modifiedStr);
Modified string: pple
In this tutorial, we learned How to Remove specific Character from a String in JavaScript language with well detailed examples.