by @saigowthamr

How to get last index of string in JavaScript

Home » javascript » 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.

const string= "what is bad";

console.log(string.length-1); // 10