「Google Apps Script」startsWithメソッドで文字の始まりを判定する

構文
対象文字列.startsWith(検索する文字列)
文字列が指定した引数で始まっていればtrueを返します。それ以外の場合はfalseを返します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function myFunction() {
const strA = "arkgame";
if (strA.startsWith("ark")) {
console.log("111");
} else {
console.log("222");
}
}
function myFunction() { const strA = "arkgame"; if (strA.startsWith("ark")) { console.log("111"); } else { console.log("222"); } }
function myFunction() {
 const strA = "arkgame";
  
  if (strA.startsWith("ark")) {
      console.log("111");
  } else {
      console.log("222");
  }
}

結果
111

Google Apps Script

Posted by arkgame