Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
lastIndexOf() 메서드는 주어진 값과 일치하는 부분을 fromIndex로부터 역순으로 탐색하여, 최초로 마주치는 인덱스를 반환합니다. 일치하는 부분을 찾을 수 없으면 -1을 반환합니다.
탐색할 문자열. 빈 값을 제공할 경우 fromIndex를 반환합니다.
fromIndex Optional탐색의 시작점으로 사용할 인덱스. 기본값은 +Infinity입니다. fromIndex >= str.length인 경우 모든 문자열을 탐색합니다. fromIndex < 0인 경우엔 0을 지정한 것과 동일합니다.
문자열 내에서 searchValue가 마지막으로 등장하는 인덱스. 등장하지 않으면 -1.
문자열의 문자는 왼쪽에서 오른쪽으로 인덱스를 매깁니다. 첫 번째 문자의 인덱스는 0이며, 마지막 문자의 인덱스는 str.length -1입니다.
참고 : 'abab'.lastIndexOf('ab', 2)는 0이 아니고 2를 반환합니다. fromIndex는 탐색의 시작점만 제한하기 때문입니다.
lastIndexOf() 메서드는 대소문자를 구분합니다. 예를 들어, 아래 예제는 -1을 반환합니다.
아래 예제는 문자열 "Brave new world" 내에서 특정 값의 위치를 확인하기 위해 indexOf()와 lastIndexOf()를 사용합니다.
| ECMAScript® 2027 Language Specification # sec-string.prototype.lastindexof |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 10월 9일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.