How to get last index of string in JavaScript
To get the last index of a string, we need to subtract the string.length
property with 1
in JavaScript.
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); // 10