Here the Startindex and Endindex describe the part of the string to be taken as a substring. Here the Endindex is optional.
It returns a new string that is part of the given string.
Example 1: This example prints the values of the sub-strings from a variable string in the console, here we use starting index value.
const str =
const result = str.substring(8);
Example 2: In this example, we are using starting and last index values.
const str =
const result = str.substring(5, 8);
Example 2: Index always starts with 0. If still, we take an index as negative, it will be considered zero and the index can’t be in fractions if it is found so, it will be converted into its just a lesser whole number.
let string =
a = string.substring(-1)
b = string.substring(2.5)
c = string.substring(2.9)
- Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 3 and above
- Opera 3 and above
- Safari 1 and above
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!