JavaScript String substring() method

The JavaScript string substring() method retrieves the part of the given string on the basis of the specified index. The original string will not be modified. It is similar to slice, the only difference is that it does not support the negative index.

Note: It returns the complete string if we do not pass any parameter in the method.

Syntax:

string.substring(start_index, end_index) 

Parameters: start_index: It represents the position of the string from where the string retrieves starts. end_index: It represents the position up to which the string is retrieved.

Return: Sub string.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var a ="HELLO WORLD!";
document.write(a.substring(0,5));
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com