Sikau

JavaScript · Day 30 · about 25 min

Arrays

A numbered shelf of items.

Many values, one name

Imagine keeping your shopping list in separate variables: item1, item2, item3… It gets silly fast. An array keeps a whole list under one name.

Making and reading arrays

const fruits = ["mango", "banana", "litchi"];

console.log(fruits);
console.log(fruits[0]);
console.log(fruits[2]);
console.log(fruits.length);

A numbered shelf: Picture a shelf with numbered spots: 0, 1, 2… Each spot holds one thing. The array is the whole shelf; the index is the spot number.

const scores = [72, 88, 95];
const last = scores[scores.length - 1];
console.log(last);
console.log(scores[5]);

The rest of this lesson

  • Changing an itemexplain
  • Arrays in real appsexplain
  • Predict the outputpredict
  • Index arithmeticpredict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript