In JavaScript, an 'array' is a list data type indicated by []
, with array 'elements' inside separated by ,
> ex)
let array1 = ['element1', 'element2', 'element3'];
individual elements of an array can be access or replaced by referencing the index of the array
The index number starts with 0
- the first element of an array has the index number of 0
, the second element 1
, the third element 2
, and so on
> ex)
let arrayPractice = ['el1', 'el2', 'el3', 'el4']; let firstEl = arrayPractice[0]; let secondEl = arrayPractice[1]; console.log(firstEl); // Prints: el1 console.log(secondEl); // Prints: el2
> ex2)
// same arrayPractice from above arrayPractice[0] = 'element1' console.log(arrayPractice); //Prints: ['element1', 'el2', 'el3', 'el4']