8.2.2. Arrays are Mutable¶
/*In programming, mutability refers to what happens when you attempt to
change a value. Remember that strings are immutable, meaning that any
change to a string results in a new string being created. In contrast,
arrays are mutable, meaning that individual items in an array can be
edited without a new array being created.*/
//Update an item in an array using bracket notation and index.
let javaScriptFrameworks = ["React", "Angular", "Ember"];
console.log(javaScriptFrameworks);
// Set the value of index 2 to be "Vue"
javaScriptFrameworks[2] = "Vue";
// Notice the value at index 2 is now "Vue"
console.log(javaScriptFrameworks);
//[ 'React', 'Angular', 'Ember' ]
//[ 'React', 'Angular', 'Vue' ]