The lastIndexOf method does pretty much what indexOf does, but it will start your search for the substring from the last. So, indexOf returns the position of the first occurrence of the substring and lastIndexOf returns the last occurrence of the substring:
const string = "this is an interesting book and this book is quite good as well.";console.log(string.lastIndexOf("this"))
The output from this is:
32
Although it might be a bit cumbersome to replace the endsWith string method with lastIndexOf, I still highly recommend you to give it a try and attempt to code it yourself. Once you're ready with your solution, check the following answer:
const string = "this is an interesting book and this book is quite good as ...