배열은 값을 가지며 각 값에는 숫자형 인덱스가 있습니다. 객체는 프로퍼티를 가지며 각 프로퍼티에는 문자열
이나 심볼 인덱스가 있습니다.
●
배열에는 순서가 있습니다. 즉,
arr[0]
은 항상
arr[1]
보다 앞에 있습니다. 반면 객체에는 그런 순서가 보장
되지 않습니다.
obj.a
가
obj.b
보다 앞에 있다고 말할 수는 없습니다.
이런 차이는 중요하긴 하지만, 다분히 이론적입니다. 그러니 객체를 정말로 객체답게 만드는
프로퍼티에 대해 생각해 봅시다.
프로퍼티
는
키
(문자열 또는 심볼)과
값
으로 구성됩니다. 객
체의 진짜 특징은 키를 통해 프로퍼티에 접근할 수 있다는 점입니다.
9.1
프로퍼티 나열
일반적으로 어떤 컨테이너의 콘텐츠를 리스트로
나열
한다고 하면, 보통 배열을 생각하지 객체
를 생각하는 사람은 별로 없습니다. 하지만 객체도 분명 컨테이너이고 프로퍼티 나열을 지원합
니다. 특별히 복잡한 작업이 필요하지는 않습니다.
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.