JavaScript String substring()
substring()
is similar to slice()
.
The difference is that start and end values less than 0 are treated as 0 in substring()
.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript String Methods</h2>
<p>The substring() method extract a part of a string and returns the extracted parts in a new string:</p>
<p id="demo"></p>
<script>
let str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.substring(7,13);
</script>
</body>
</html>
===============
Result:
JavaScript String Methods
The substring() method extracts a part of a string and returns the extracted parts in a new string:
Banana
No comments:
Post a Comment
Add your comment here.