Substr-2

 

Javascript Substr function is used to extract the string out of string and it has two parameters where first one is starting point and second one is optional and that defines the length or number of characters that should be extracted out.

 
 
 
<!DOCTYPE html> <html> <head> <title>Welcome to LearnKode - A code learning platform</title> </head> <body> <button onclick="extractSubpart()">Extract subpart of string</button> <p id ="sample"></p> <script> function extractSubpart() { var str = "I LOVE LEARNKODE"; var result = str.substr(2); document.getElementById("sample").innerHTML=result; } </script> </body> </html>
Output