๐ย Reference
๐ย Chapter
lastIndexOf(searchString)
lastIndexOf(searchString, position)
str
ย ๋ค์์๋ถํฐย (index: 0
) ์ง์ ํย searchString
๊ฐ ์ฒ์์ผ๋ก ๋ฐ๊ฒฌ๋๋ ์์น์ย index
ย ๋ฐํํ๋ค. ๋ฐ๊ฒฌํ์ง ๋ชปํ๋ฉดย -1
์ ๋ฐํํ๋ค.undefined
๋ฅผ ์ ๋ฌํ๋ฉด lastIndexOf()
๊ฐ ๋ฌธ์์ด "undefined
"๋ฅผ ๊ฒ์ํ๊ฒ ๋๋๋ฐ, ์ด๋ ๊ฑฐ์ ์ํ๋ ๋ฐ๊ฐ ์๋๋ค.์์ 1
const paragraph = "I think Ruth's dog is cuter than your dog!";
const searchTerm = 'dog';
console.log(
`Index of the last ${searchTerm} is ${paragraph.lastIndexOf(searchTerm)}`,
);
// Expected output: "Index of the last "dog" is 38"