Learn JavaScript
Object
7.10
Lesson

Add object property using bracket notation

We have an object subjects in the editor.

If we try to add the value Mathematics to the key 104 using the dot operator it gives an error.

This is because, the name of the key is not a proper variable name. Now, to add the value of this property, we must use the bracket notation.

In the example given above, we add the value Mathematics to the 104 key in the object using bracket notation.