Member-only story
Javascript String Methods with example
In this tutorial, you will learn the javascript string methods with examples one by one as given below
Example:-
<html>
<head>
<title>Javascript string methods</title>
</head>
<body> <p>Below paragraph returns the length of the given string</p> <p id="demo"></p>
<script>
let text = "Helloworld"; document.getElementById("demo").innerHTML = text.length;
</script>
</body>
</html>
Output:- Below paragraph returns the length of the given string
Also read, Object in Javascript with example
slice():- This function extracts some part of the given string and returns the extracted string. This string method takes two parameters as the start position index and the end position index. Please note that the start position index starts from zero and the end position index can not take place in the extracted string.
Example:-
<html>
<head>
<title>Javascript string methods</title>
</head>
<body>
<p>Below paragraph extracts a part of the string and returns the extracted string</p>
<p id="demo1"></p>
<script> let text = "Helloworld"; document.getElementById("demo1").innerHTML = text.slice(0,5); </script>
</body>
</html>
Output:- Below paragraph extracts a part of the string and returns the extracted
…