📎
JavaScript入門〜基本構文オブジェクト〜
オブジェクト
オブジェクトの宣言
app.js
let profile = {
名前:'緑一郎',
性別:'男',
身長:'170cm',
体重:'60kg'
}
console.log(profile);

プロパティの追加
app.js
profile['趣味'] = '読書';
console.log(profile);
→プロパティprofileに 趣味:読書 を追加

プロパティの変更
app.js
profile['性別'] = '女'
console.log(profile);
→性別:男を女に変更

プロパティの削除
app.js
delete profile['体重'];
console.log(profile);
→プロパティ体重を削除する

オブジェクトのサイズ取得
app.js
let len = Object.keys(profile).length;
console.log(len);
→オブジェクト自体にはlengthが使用できないので、Objects.keys()の中にオブジェクトを入れてあげる事で、lengthでキーの数を取得できる

Discussion