Skip to content

Instantly share code, notes, and snippets.

@Jameshsu0407
Created December 11, 2022 04:44
// 語法
// str.lastIndexOf(searchValue[, fromIndex])
// searchValue為要尋找的對象
// fromIndex為從特定索引值開始向左找起,選填
let str = 'One is all, All is one.';
str.lastIndexOf('one')
// 19
str.lastIndexOf('w')
// -1
str.lastIndexOf('is', 10)
// 4
str.lastIndexOf('is', 30)
// 16
// fromIndex >= 字串長度,就會搜尋整個字串
str.lastIndexOf('is', -1)
// -1
// fromIndex < 0,代表fromIndex=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment