Working With Arrays
Bracket Notation and Index
As previously discussed, arrays are an ordered collection where each item can be accessed via index. Similar to strings, an index in an
array is the number order given to items. Individual items can be accessed using bracket notation (
Indexes are zero-based, going from
Use bracket notation and index to access items in an array.
Notice above that
undefined was printed out when index 4 was referenced.
undefined is returned when you request an index
that the array does not contain.
undefined more later in the class.
undefined will be returned for any index that is outside of the array’s index range.
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.
[ 'React', 'Angular', 'Ember' ] [ 'React', 'Angular', 'Vue' ]