Javascriptの配列(Object型編)の基本まとめ
前回に続きJavascriptの配列の基本についてです。今回はあくまでObject型についてです。
[ad#top-1]
基本形
const member = { name: 'Yamada Taro', age: 62, }; console.log(member); //出力 //{name: "Yamada Taro", age: 62} console.log(member.name); //出力 //Yamada Taro
要素の追加と削除
const member = { name: 'Yamada Taro', age: 62, }; member.email = 'yamada@aaa.jp'; console.log(member); //出力 //{name: "Yamada Taro", age: 62, email: "yamada@aaa.jp"} delete member.age; console.log(member); //出力 //{name: "Yamada Taro", email: "yamada@aaa.jp"}
KeyとValueの操作
const member = { name: 'Yamada Taro', age: 62, }; console.log(Object.keys(member)); console.log(Object.values(member)); //出力: //["name", "age"] //["Yamada Taro", 62] Object.keys(member).forEach(key => { console.log(key +" : "+ member[key]); }); //出力: //name : Yamada Taro //age : 62
二重配列
const members = { member1: { name: 'Yamada Taro', age: 62, }, member2: { name: 'Suzuki Takashi', age: 48, }, }; console.log(members); //出力 //member1: {name: "Yamada Taro", age: 62} //member2: {name: "Suzuki Takashi", age: 48}__proto__: Object console.log(members.member1); //出力 //{name: "Yamada Taro", age: 62} console.log(members.member1.name); //出力 //Yamada Taro
[ad#ad-1]
スポンサーリンク