We have declared an array of selected month names let summer = ["June", "July", "August"];
. We want to change the value "July"
stored in the array to the number 7
:
summer[1] = 7;
- We cannot do this (an array can only contain elements of the same type).
summer.July = 7;
summer[0] = 7;
Answers Explanation & Hints:
To change the value “July” stored in the array In JavaScript arrays, elements can be of different types, so you can replace an element in the array with a value of a different type. By using Therefore, after executing |