JavaScript문자열lastIndexOf

lastIndexOf문자열

마지막으로 등장하는 위치를 반환합니다.

문법

str.lastIndexOf(searchStr, fromIndex?)

예제

아래 값을 입력하면 예제에 즉시 반영됩니다.

const
console
lastIndexOf
const text = "hello world hello";
console.log(text.lastIndexOf("hello"));    // 12
console.log(text.lastIndexOf("world"));    // 6