LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Tuesday, March 6, 2018

配列の要素をつなげる 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

スプレッドシートA列にある複数のテキストをスライドに追加したい(Google Apps Script)

今回Google Apps Scriptでやりたいこと GoogleスプレッドシートA列にある複数の値を取得して Googleスライドに渡して 図形オブジェクトのテキストとして追加したい ① スプレッドシートのA列に値を入れておく ② Code.gsのinsertNewShape...