The conversation between human and AI assistant.
How do I find the position of the last occurrence of a character in a string without using .lastIndexOf()?
Okay, thanks. Can you walk me through how to do that?
Sure. You would create a regex with the character you're looking for, then use .exec() on the string backwards with a while loop until it returns null. Each time it returns a match, update the index to that index. Once the loop is finished, you'll have the index of the last occurrence of the character.