/string.lastIndexOf().js Secret
Created
December 11, 2022 04:44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 語法 | |
// 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