Hi everyone! I'm the author of code.mu :)
I'd love to chat with my non-Russian audience. I'm looking for your feedback on the site and the translation quality. Let's chat:)
⊗jsPmObEA 86 of 504 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.

← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline