var shape = {
circle: {
colors: {
blue: "#0066FF",
red: "#FF3300"
}
},
radius: 20
};
그래서 나는 객체 "파란색"에 접근하려고했지만 그것을 할 수 없었다. "파란색"개체에 어떻게 액세스합니까?
javaScript에서 중첩 된 객체에 액세스하는 두 가지 방법 :
// use this way for only some special cases like
// when using reserved keywords or
// using spaces or special characters or
// if your property starts with number.
alert(shape.circle.colors["blue"]);
또는
alert(shape.circle.colors.red);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다