How to use substr() method In Javascript
The substr() method is used to remove a character from a specific index within the string.
It extracts portions of a string between specified parameters and then joins the parts before and after the character to be removed.
Syntax:
string.substr(start, length)
Example: This example shows the above-explained approach
function removeCharacter(position) {
originalString = "w3wiki";
newString =
originalString.substr(0, position - 1)+
originalString.substr(
position,
originalString.length
);
console.log(newString);
}
removeCharacter(6);
Output
GeeksorGeeks
Remove a Character From String in JavaScript
We are given a string and the task is to remove a character from the given string. We have many methods to remove a character from a string that is described below.
Table of Content
- Method 1: Using JavaScript replace() Method
- Method 2: Using JavaScript replace() Method with a Regular Expression
- Method 3: Using JavaScript slice() Method
- Method 4: Using JavaScript substr() method
- Method 5: Using JavaScript split() and join() methods
- Method 6: Using JavaScript splice() Method