습니다. 하지만 자바스크립트가 그런 순서를 명시적으로 보장하는 것도 아니고, 브라우저나 노
드 등의 프로그램에서 속도나 효율 향상을 목적으로 언제든 바꿀 수도 있습니다. 따라서 입증
할 수 없는 테스트를 근거로 확실하다는 착각에 빠지지 마십시오. 객체 프로퍼티에는 순서가
없습니다
.
주의할 점은 충분히 숙지했으니 이제 객체의 프로퍼티를 나열하는 방법을 알아봅시다.
9.1.1
for
...
in
그동안은 객체 프로퍼티를 나열할 때
for
...
in
을 주로 사용했습니다. 문자열 프로퍼티가 몇
개 있고 심볼 프로퍼티가 하나 있는 객체가 있다고 합시다.
const
SYM
=
Symbol
();
const
o
= {
a
:
1
,
b
:
2
,
c
:
3
, [
SYM
]:
4
};
for
(
let
prop
in
o
) {
if
(!
o
.
hasOwnProperty
(
prop
))
continue
;
console
.
log
(`${
prop
}: ${
o
[
prop
]}`);
}
상당히 단순해 보입니다만,
hasOwnProperty
가 무슨 의미인지 궁금한 독자도 있을 겁니다.
hasOwnProperty
는 이 장 후반에 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.