Array Basics

👨‍💼 We need to store and access multiple values. Arrays let us keep an ordered list of items.
Creating an array:
const fruits = ['apple', 'banana', 'cherry']
Accessing elements (zero-indexed):
console.log(fruits[0]) // "apple" (first element)
console.log(fruits[1]) // "banana" (second element)
console.log(fruits[2]) // "cherry" (third element)
🐨 Open and:
  1. Create an array colors with at least 3 color names
  2. Log the first element
  3. Log the last element (hint: use colors.length - 1)
  4. Change the second element to a different color
  5. Log the entire array
💰 You can modify array elements:
fruits[1] = 'blueberry' // Changes "banana" to "blueberry"

Please set the playground first

Loading "Array Basics"
Loading "Array Basics"