Sikau

JavaScript · Day 38 · about 25 min

Lists of objects

Contacts, recipes and more.

The best of both

Your phone's contacts are a list of cards. Put objects inside an array and you can model almost anything: products in a shop, students in a class, songs in a playlist.

An array of objects

const menu = [
  { name: "momo", price: 180, veg: false },
  { name: "dal bhat", price: 250, veg: true },
  { name: "aloo paratha", price: 120, veg: true },
];

console.log(menu[1].name);

for (const dish of menu) {
  console.log(`${dish.name} — Rs ${dish.price}`);
}

The rest of this lesson

  • map, filter and find on objectsexplain
  • Data from the real worldexplain
  • Predict the outputpredict
  • Names of the veg dishespredict
  • Your turnwrite code
  • Challengechallenge
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 68 lessons of JavaScript