offline version v3


⊗jsPmObEA 86 of 502 menu

Adding elements to objects in JavaScript

You can add new elements to objects by writing them to the desired keys. Let's see how it's done. Let's have the following object:

let obj = {};

Let's add new elements to it:

obj['a'] = 1; obj['b'] = 2; obj['c'] = 3;

You can use alternative syntax:

obj.a = 1; obj.b = 2; obj.c = 3;

Check the content of the object:

console.log(obj);

Create an empty object and then fill it with values.

enru