The JavaScript string substr() method retrieves the part of the given string on the basis of the specified starting position and length. The 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 return a substring from the specified string.
Example:
<!DOCTYPE html> <html> <body> <script> var a ="HELLO WORLD!"; document.write(a.substr(0,5)); </script> </body> </html>
Please follow and like us: