Javascript Notes: 02 – Arrays
Use Arrays to store lists. (Note: Technically an Array is an object)
An ARRAY is a data structure that we use to represent a list of items.
Example 1:
let selectedColors = [‘red’, ‘blue’];
console.log(selectedColors);
In our example the array has two elements ‘red’ and ‘blue’. The index of red is 0 and the index of blue is 1. To access an element in array use the index.
Remember, Javascript is a dynamic language and variables can change at runtime.
Example 2:
let selectedColors = [‘red’, ‘blue’];
selectedColors[2] = ‘green’;
console.log(selectedColors);
Example 3:
let selectedColors = [‘red’, ‘blue’];