-
Arrays are fairly similar to objects, they have different stored values and syntax, but can be used for almost anything.
-
Here is the same code as objects but in an array:
var choosePill = ['Red', 'Blue', 2];
var choice = choosePill[0];
console.log(choice); // Outputs 'Red'
Reminder: Most programming languages start from 0, not 1, so when we access the choosePill
variable, we grab the value from the 1st
position.
- Arrays are extremely important when storing multiple values within a variable.
- This way we don't have to write 100 variables and instead can store them all in a single variable, this is an array.
- There are multiple ways to write an array, but this one is simplest and most basic version is the example above.