See also
연관 배열 : C++의 맵(map), 파이썬의 딕셔너리(dictionary)가 이에 해당합니다.
> var cheol = {
name: "Cheol Kang",
"height": 180,
handle: {
SPARCS: "cancho",
twitter: "cornchz"
},
age: function () {
return currentYear - 1990 + 1;
}
};
> cheol['name'];
'Cheol Kang'
> cheol.height;
180
Note
> var props = ['name', 'height'];
> for (var i in props) {
var prop = props[i];
console.log(cheol[prop]); // cheol.prop은 전혀 다른 의미입니다.
}
Cheol Kang
180
> cheol.girlFriend; // undefined
> cheol['car']; // undefined
> cheol.car || '(none)';
'(none)'
> cheol.girlFriend // undefined
> cheol.girlFriend.car
TypeError: Cannot read property 'car' of undefined
at [object Context]:1:2
// (생략)
> cheol.girlFriend && cheol.girlFriend.car // undefined
> cheol.name = 'Cheol';
> cheol['job'] = 'student';
> cheol.name;
'Cheol'
> delete cheol.name;
> cheol.name; // undefined
> var obj = new Object();
> var objRef = obj;
> obj.one = 1;
> obj.one === objRef.one
true
> obj === objRef
true
> objRef = new Object();
> objRef.one = 'one';
> obj.one === objRef.one
false
> obj === objRef
false