Creating Arrays
We create an array by enclosing items in square brackets and separating them with commas. For example:
let shoppingList = ["Apples", "Chocolate", "Bread rolls"];
This creates an array with the elements "Apples"
, "Chocolate"
, "Bread rolls"
and stores it in the variable shoppingList
.
Arrays can store any data type — we can have an array that contains only one data type, or an array that contains different data types. For example:
let array = ["text", 123, true];
This array has three elements: "text"
, 123
, and true
. The first element is a string, the second element is a number, and the third element is a boolean type.
Instructions
Create an array with the values "Josh"
, "Tim"
, "Emily"
in that order. Store it in a variable named coworkers
.
Print the value of the variable coworkers
.
Start programming for free
2/10