![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
[ノンプロ研]GAS初級講座8期第4日目 オブジェクト
-
TsujiKenzo
- 731
- 0
- 0
- 0
![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
オブジェクト、まずはプロパティから。 誰も挫折させない講座が、そこにある! (できるだけ丁寧に説明します💦) #ノンプロ研
2021-03-17 20:21:26![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
○オブジェクトの参照法(ブラケット記法) オブジェクト['プロパティ'] const person = {name: 'Bob', gender: 'male', age: 25}; console.log(person['name']); ブラケットとは:角括弧[]のこと wa3.i-3-i.info/word11590.html #ノンプロ研 #GAS初心者講座
2021-03-17 20:24:47![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
ブラケット記法のときはコンテンツアシストは出てこないのね。 #ノンプロ研 #GAS初級講座
2021-03-17 20:26:35![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
○プロパティの追加、値の上書き(ドット記法) オブジェクト.プロパティ = 値 const person = {name: 'Bob', gender: 'male', age: 25}; person.name = ‘John’; person.favorite = ‘Coffee’; console.log(person.name, person.favorite); #ノンプロ研 #GAS初心者講座
2021-03-17 20:27:51![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
IT用語では大カッコだけど、ブラケットって元々は何かと思ったらカーテンレールとか支える棒のこというんだ…! #ノンプロ研 #GAS初心者講座
2021-03-17 20:28:26![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
○プロパティの追加、値の上書き(ブラケット記法) オブジェクト[‘プロパティ’] = 値 const person = {name: 'Bob', gender: 'male', age: 25}; person[‘name’] = ‘John’; person[‘favorite’] = ‘Coffee’; console.log(person[‘name’], person[‘favorite’]); #ノンプロ研 #GAS初心者講座
2021-03-17 20:29:05![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
上書き:person.name = ‘John’; 追加:person.favorite = ‘Coffee’; #ノンプロ研 #GAS初心者講座 twitter.com/Ktane6/status/…
2021-03-17 20:30:43![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
上書き:person[‘name’] = ‘John’; 追加:person[‘favorite’] = ‘Coffee’; #ノンプロ研 #GAS初心者講座 twitter.com/Ktane6/status/…
2021-03-17 20:31:25![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
これはいい発見ですね。そうですね。入力補完が効くのは「ドット記法」だけです。 #ノンプロ研 #GAS初級講座 twitter.com/bagoodfriend1/…
2021-03-17 20:31:59![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
ほめられた。 #ノンプロ研 #GAS初級講座 twitter.com/TsujiKenzo/sta…
2021-03-17 20:33:38![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
ドット記法とブラケット記法: →書きやすいのはドット記法 →ブラケット記法はプロパティを変数・定数で指定したいときに便利 qiita.com/TakanoriOkawa/… #ノンプロ研 #GAS初心者講座
2021-03-17 20:35:46![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
気になっていたfor in(調べてはいない・・・) #ノンプロ研 #GAS初級講座 予習はブレイクアウトループのお題だけ。。。
2021-03-17 20:39:43![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
☆プロパティを変数・定数で指定 *prop使用 function myFunction() { const person = {name: 'Bob', age: 25}; person.name = 'Tom'; person['job'] = 'Engineer'; const prop = 'favorite'; person[prop] = 'Coffee'; console.log(person); } #ノンプロ研 #GAS初心者講座
2021-03-17 20:41:10![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
○for...in文 オブジェクトの全てのプロパティについて繰り返す for (const 定数 in オブジェクト) { //処理 } ※for in文は取り出し順が保証されない techacademy.jp/magazine/45236 #ノンプロ研 #GAS初心者講座
2021-03-17 20:42:51![](https://tgfile.tg-static.com/static/web/img/placeholder.gif)
for…in文で for (const 定数(例.key) in オブジェクト) { //処理 } 定数(例.key)はオブジェクトのプロパティ(属性)を取り出すということで、気になってtypeofでデータ型を出力してみたらstring型だった。 #ノンプロ研 #GAS初級講座
2021-03-17 20:49:35