JavaScript Substr function is used to extract characters from string. Two parameters one is start index and 2nd is number of characters. var str = "I Love LearnKode."; var result = str.substr(1, 5); See the code snippet:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
</head>
<body>
<button onclick="extractSubpart()">Click to extract subpart of string</button>
<p id ="sample"></p>
<script>
function extractSubpart()
{
var str = "I Love LearnKode.";
var result = str.substr(1, 5);
document.getElementById("sample").innerHTML=result;
}
</script>
</body>
</html>