JavaScript substr() Function Example

JavaScript substr() function get the sub string from two specified position parameter value.

Syntax

string.substr(start, length)

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>JavaScript str.substr() function</title>
</head>
<body>
    <script type="text/javascript">
        var str="Hello Student";
        document.write(str.substr(0,13)+"<br />");
        document.write(str.substr(3,7)+"<br />");
        document.write(str.substr(3,5));
    </script>
</body>
</html>

Run it...   »

Example Result