×

javascript · level 1 · unit 6 · lesson 4

  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

Arrays can tell you what is inside them.

Arrays can answer questions. asks: is jam in here? It gives back true or false, so it fits straight into an if.

tells you where jam is, as an index. If it is not there at all, you get -1, because no real place has that number.

For other questions, like which number is the smallest, search by hand. Walk through the array with a loop, and use an if to keep the best one so far.

let fridge = ["milk", "cheese", "jam"];
console.log(fridge.includes("jam"));
console.log(fridge.indexOf("cheese"));
console.log(fridge.indexOf("ham"));

Searching is case-sensitive, so "Jam" and "jam" do not match.