freeCodeCamp/guide/russian/javascript/tutorials/declare-javascript-objects-.../index.md

34 lines
963 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Declare JavaScript Objects as Variables
localeTitle: Объявление объектов JavaScript как переменных
---
Это простой формат. Вы объявляете свою переменную и имеете ее равным объекту в форме `{ key: value}`
```
var car = {
"wheels":4,
"engines":1,
"seats":5
};
```
Вы можете получить доступ к свойствам объекта с помощью точечной нотации или скобки.
Использование точечной нотации:
```javascript
console.log(car.wheels); // 4
```
Использование обозначения в виде скобок:
```javascript
console.log(car["wheels"]); // 1
```
Использование обозначения динамической скобки:
```javascript
var seatsProperty = "seats";
console.log(car[seatsProperty]); // 5
```