Suggest an editImprove this articleRefine the answer for “Key-value”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)A **key-value pair** is the foundation of data storage in JavaScript objects (and in many other structures): the key is the property name, and the value is the data that corresponds to that name. **Key point:** keys are always unique within a single object and are usually strings (or `Symbol`s), even when written as a number.Shown above the full answer for quick recall.Answer (EN)ImageThe **"key-value" pair (key-value)** is the foundation of data storage in JavaScript objects (and in many other structures). The **key** is the property name, the **value** is the data that corresponds to that name. --- ### Detailed explanation In JavaScript, an object stores data as a set of such pairs: ```javascript const user = { name: 'Tim', // key → value age: 25, city: 'Berlin' }; ``` Here: - `name`, `age`, `city` are the **keys** (or "property names"), - `'Tim'`, `25`, `'Berlin'` are the **values**. Each property is a **key-value pair** that describes a piece of data. --- ### How keys work - Keys are always **unique** within a single object. - They are usually **strings** (or `Symbol`s), even if you write a number: ```javascript const obj = { 1: 'a', 2: 'b' }; console.log(Object.keys(obj)); // ["1", "2"] ``` --- ### How to get a value by key ```javascript console.log(user.name); // "Tim" console.log(user['city']); // "Berlin" ``` Access is possible: - via **dot notation**, if the name is known in advance; - via **brackets**, if the key is stored in a variable. ```javascript const key = 'age'; console.log(user[key]); // 25 ``` --- ### What key-value pairs consist of You can see them as an array: ```javascript console.log(Object.entries(user)); ``` Output: ```javascript [ ['name', 'Tim'], ['age', 25], ['city', 'Berlin'] ] ``` Each pair is `[key, value]`. --- ### Where else the "key-value" principle appears | Structure | Example | What it stores | |---|---|---| | **Object** | `{ name: 'Tim' }` | Keys → strings | | **Map** | `map.set('role', 'admin')` | Keys → any type | | **URLSearchParams** | `?id=1&name=Tim` | Keys and values from a URL string | | **FormData** | `form.append('email', 'tim@example.com')` | Form fields | --- ### SUMMARY | Element | Description | |---|---| | **Key** | The property name used to access the data | | **Value** | The data associated with that key | | **Example** | `{ "key": "value" }` | | **Typical storage format** | `{ name: 'Tim', age: 25 }` |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.