How to get last index of string in JavaScript
To get the last index of a string JavaScript, we need to subtract the string.length
property with 1
. So, it returns the last index of a string.
In this below example, we are getting the last value index of the following string.
const string= "what is bad";
console.log(string.length-1);
Output:
10