Google Apps Script で、https
で始まる文字列判定をしたかったのですが、
以下のような実装をしたところ、
if(url.startsWith('https')) {
// https の場合の処理..
} else {
// http の場合の処理..
}
関数が見つからないエラーが発生しました。
TypeError: オブジェクト
https://www.monotalk.xyz/blog/google-apps-script-logger%E3%83%A9%E3%82%A4%E3%83%96%E3%83%A9%E3%83%AA-betterlog%E3%82%92%E4%BD%BF%E3%81%86/ で
関数 startsWith が見つかりません。(行 57、ファイル「update-amp-cache」)
以下、Stack Overflow の記事に記載がありましたが、
現在(2017/08/08)のところ、Google Apps Script では、startswith は サポートされていないようです。
javascript - String starts with in Google Script - Stack Overflow
実装は、記事にある通り、indexOf を使う形で修正しました。
if(url.indexOf('https') == 0) {
// https の場合の処理..
} else {
// http の場合の処理..
}
以上です。
コメント