「Google Apps Script」lastIndexOfメソッドで文字列検索開始位置を指定する

構文
対象文字列.lastIndexOf(検索する文字列, 検索を始める位置)
文字列を末尾から検索して出現した位置(数値)を返します。
引数1は検索する文字列です。
引数2は検索を開始する位置です。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function myFunction() {
const target = "東京関東地方";
console.log(target.lastIndexOf("東",4));
console.log(target.lastIndexOf("東",3));
console.log(target.lastIndexOf("東",2));
console.log(target.lastIndexOf("東",1));
console.log(target.lastIndexOf("東",0));
}
function myFunction() { const target = "東京関東地方"; console.log(target.lastIndexOf("東",4)); console.log(target.lastIndexOf("東",3)); console.log(target.lastIndexOf("東",2)); console.log(target.lastIndexOf("東",1)); console.log(target.lastIndexOf("東",0)); }
function myFunction() {
 
  const target = "東京関東地方";
  console.log(target.lastIndexOf("東",4)); 
  console.log(target.lastIndexOf("東",3));
  console.log(target.lastIndexOf("東",2)); 
  console.log(target.lastIndexOf("東",1)); 
  console.log(target.lastIndexOf("東",0)); 

}

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
3
3
0
0
0
3 3 0 0 0
3
3
0
0
0

 

Google Apps Script

Posted by arkgame