Mastering JavaScript Substring: Syntax, Example, and works

What is JavaScript substring?

We use the JavaScript substring to find one part of the string, in this the two parameters are used, the starting index and the ending index.

JavaScript Substring Method Syntax

Through the JavaScript substring() method, characters between two indices (positions) are taken out of a string and the substring is returned. The substring() technique removes.

Starting index : This is the number on which to extract the substring. If someone gives negative number or does not give any number then it is called 0 number.

Ending index : This is the number at which to end the extraction. If no number comes up. So the Javascript Substring will contain all the code from the first code line to the last . If negative number comes. then its string length.

Extracting a substring from the beginning of the string example

Substring is used to extract the substring line starting from the starting code of the string.



Extracting a substring to the end of the string example

Substring is used to extract a substring from index 11 to the end of the string.


” Substring”

Extracting domain from the email example

“Substring” Uses the substring() with the indexOf() to extract the domain from the email.

Read More : What is Data Science

How it works:

1: The indexOf() returns the position of the “@” character.

2: That start from the index of @ plus 1 to the end of the string.Then the substring returns the domain.

Leave a Comment