offline version v3


⊗jsPmObInr 80 of 502 menu

Objects in JavaScript

JavaScript has special data structures called objects (in other programming languages they are called associative arrays or hashes).

Objects are created using braces { }, inside which the elements of this object are written in the format key: value.

Let's create an empty object:

let obj = {};

And now let's create an object with data:

let obj = {1: 'a', 2: 'b', 3: 'c'};

Retrieve an element of the object by its key:

console.log(obj[1]); // shows 'a'

Create an object with keys from 1 to 7, containing the names of the days of the week as values. Display all of its elements.

enru