Skip to content
JS FAQ - JavaScript Guides Online

Get answers to your JavaScript questions. Explore detailed how-to guides, code examples, and best practices for beginners and developers.

  • Home
  • Home
Books
Home » lastIndexOf
How to find the last occurrence of a substring in JavaScript
Posted inStandard Objects: Array

How to find the last occurrence of a substring in JavaScript

Posted inStandard Objects: ArrayTags: js string, lastIndexOf, search, string
JavaScript’s lastIndexOf method works for fixed strings but not regex patterns. To find the last regex match, use global regex with exec or matchAll to iterate all matches and capture the last one. Backward searches can be simulated by slicing strings before applying regex.
Read More
Copyright 2026 — JS FAQ - JavaScript Guides Online. All rights reserved.
Scroll to Top