×

typescript · level 1 · unit 6 · lesson 1

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

An keeps many values together in one box.

An array is like a shopping list: many values kept in order, in one box. Write the items inside square brackets, [ and ], with a comma between each.

The type label is the type followed by empty square brackets. string[] means an array of strings, and number[] an array of numbers. Only that kind of item may go in.

.length tells you how many items the array holds. Show the whole array with console.log and you see every item inside square brackets.

let shopping: string[] = ["bread", "milk", "eggs"];
let prices: number[] = [1.2, 0.9, 2.5];
console.log(shopping);
console.log(prices.length);

When you show an array, the items appear with no spaces after the commas.