2011年2月16日 星期三

javascript的lastIndexOf()方法

javascript的lastIndexOf(searchstring ,postionindex)

searchstring:要搜尋的字串
postionindex:要搜尋的位置索引(可不輸入)

方式:
  1. 無postionindex: 則由搜尋文由右向左找尋第一個searchstring, 再由搜尋文開始計算至找尋到的字串位置即為值, 無則回傳-1
  2. 有postionindex: 由搜尋文開始計算至postionindex, 再由該點由右向左找尋第一個searchstring, 再由搜尋文開始計算至找尋到的字串位置即為值, 無則回傳-1
exp code:


搜尋文:
搜尋字串:
搜尋位置索引:

結果:

explain:
搜尋文="Welcome to my world!"
搜尋字串="m"

postionindex      結果
無                            11
0                              -1
1                              -1
2                              -1
3                              -1
4                              -1
5                              5
6                              5
7                              5
8                              5
9                              5
10                            5
11                           11