One way we can create an array is to use an array literal. An array literal creates an array by wrapping items in square brackets []
. Remember from the previous exercise, arrays can store any data type — we can have an array that holds all the same data types or an array that holds different data types.
Let’s take a closer look at the syntax in the array example:
- The array is represented by the square brackets
[]
and the content inside. - Each content item inside an array is called an element.
- There are three different elements inside the array.
- Each element inside the array is a different data type.
We can also save an array to a variable. You may have noticed we did this in the previous exercise:
let newYearsResolutions = ['Keep a journal', 'Take a falconry class', 'Learn to juggle'];