[JS] Object
An Object is logically a collection of properties.
Properties are identified using key values. A property key value is either an ECMAScript String value or a Symbol value. All String and Symbol values, including the empty String, are valid as property keys. A property name is a property key that is a String value.
Property keys are used to access properties and their values(p.89)
- 物件是由許多 屬性(properties) 所組成
- 物件的屬性也就是所謂的
key,使用key來取得物件的屬性和對應的值 - key 一定要是
string或symbol;即使是空字串也可以拿來當作 key
var user = {
name: 'John',
age: 18,
hobby: 'soccer',
isMarried: false,
spells: ['shazam', 'abrakadra', 'boo'],
shout: function () {
console.log('AHHHHH!');
},
};
console.log(user.name); // John
console.log(user[age]); // 18