이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Objects group related data
- An object stores named values together:
{ key: value, ... }. - Reach a value by its key with a dot:
person.name. - An object is perfect for one thing that has several details.
![const pet = { name: "Rex", age: 3 }; pet.name is "Rex", pet["age"] is 3, pet.age = 4 changes the age](/static/code/javascript/object.png)
English
let person = { name: "Ada", age: 36 };
console.log(person.name); // → Ada
console.log(person.age); // → 36
탐색하기
A key looks up a value
An object maps each 검색 기준 to a 명암(value). obj.key looks one up instantly.
English
Change or add a property
- Assign to
obj.keyto change a value — or to add a brand-new one.
English
let car = { speed: 0 };
car.speed = 60; // change an existing key
car.colour = "red"; // add a new key
console.log(car.speed); // → 60
English
Watch out
- A missing key gives
undefined, not an error:person.height→undefined. person["name"]does the same asperson.name— handy when the key sits in a variable.
English
Common mistakes
- Read a value with
obj.keyorobj["key"]. - A missing key gives
undefined, not an error.
English
Now you try
- Read and change object properties.
- Press Check answer to test it.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
let book = { title: "CS", pages: 200 }. Log the book's title with book.title (it is CS).
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
let car = { speed: 0 }. Change car.speed 부터 80, then log it.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Create an object p with a property x set to 3 and a property y set to 4.
출력을 보려면 '실행'을 클릭하세요.