How to use the substring() method In Javascript
In javascript the substring method returns a substring of string based on the index numbers provided as arguments.
Syntax:
str.substring(index);
Example: In this example, we will delete the first character of the string by providing an index value.
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Delete first character of a string in JavaScript
</title>
</head>
<body>
<h3>
Delete first character
of a string
</h3>
<p>
Click on button to display the
extracted part of the string
</p>
<button onclick="myGeeks()">
Click Here!
</button>
<p id="GFG"></p>
<script>
function myGeeks() {
let str = "w3wiki";
let result = str.substring(1);
document.getElementById("GFG").innerHTML
= result;
}
</script>
</body>
</html>
Output:
Delete first character of a string in JavaScript
In this article, we will delete the first character of a string in Javascript. There are many ways to delete the first character of a string in JavaScript.
Below are the methods used to delete the first character of a string in JavaScript:
Table of Content
- Using slice() Method
- Using substr() Method
- Using replace() method
- Using the substring() method
- Using String.prototype.split()
- Using Array shift()