JavaScript String substr() method

The JavaScript string substr() method retrieves the part of the given string on the basis of the specified starting position and length. Original string will not be modified.

Syntax:

string.substr(position, length) 

Parameters:
position: It represents the position of the string from where the string retrieves starts.
length: It represents the number of characters to be retrieved.

Return:
It will returns sub string from the specified string.

Example:

<!DOCTYPE html>
<html>
<body>
<script>   
var a ="HELLO WORLD!";  
document.write(a.substr(0,5));  
</script>
</body>
</html>

Output:

HELLO
Please Share