Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2018年3月6日火曜日

配列の要素をつなげる joinを使う


配列の要素をつなげて文字列にするコードの例です


こういう配列から
var array = ["hello","hi","hey"];


こういう文字列を作ってみます

  • hello,hi,hey
  • hellohihey
  • hello&hi&hey




コード.gs
function array_join(){
  var array = ["hello","hi","hey"];
  var with_comma = array.join();
  var without_comma = array.join("");
  var with_space = array.join("&");
  Logger.log([with_comma, without_comma, with_space]);
}
意訳
この処理は以下を実行する
配列を用意する
カンマでつなげた文字列(つなげる文字を指定しないとカンマでつながる)
要素を区切らずにつなげた文字列(つなげる文字を空文字にする)
要素を&でつなげた文字列
それぞれの結果をログに出す




実行結果


Latest post

Googleドライブ内の音声ファイルをiframe内で再生したい

iframe の src にGoogleドライブ内の音声ファイルを埋め込む例です (今回試した音声ファイルはmp3) Code.gs function doGet () { return HtmlService . createTemplateFromFile ( ...