Learn
In the previous exercise, you learned how to access elements inside an array or a string by using an index. Once you have access to an element in an array, you can update its value.
let seasons = ['Winter', 'Spring', 'Summer', 'Fall']; seasons[3] = 'Autumn'; console.log(seasons); //Output: ['Winter', 'Spring', 'Summer', 'Autumn']
In the example above, the seasons
array contained the names of the four seasons.
However, we decided that we preferred to say 'Autumn'
instead of 'Fall'
.
The line, seasons[3] = 'Autumn';
tells our program to change the item at index 3 of the seasons
array to be 'Autumn'
instead of what is already there.
Instructions
1.
Change the second element of the array groceryList
to 'avocados'
.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.