Start learning free

LESSON 124 OF 671 · DICTIONARIES

Updating Dictionary Values in JavaScript

Lesson

You can update an existing value in a JavaScript object by assigning a new value to an existing key:

const scores = {"Alice": 95, "Bob": 87};

scores["Alice"] = 99;     // update existing key
scores["Charlie"] = 72;   // add new key

Note: even though scores is declared with const, you can still modify its properties — you just can't reassign the variable itself.

const d = {x: 1};
d.x = 100;    // x is now 100
d.y = 200;    // new key "y" added

Assignment
Follow the Coding Tutorial and update Alice's score to 99!


Hint
Use scores["Alice"] = 99.

STEP 1 OF 1
    Ctrl + Enter to check