Loading
0x50Lesson 6 of 6

Group data with arrays and objects

Store ordered lists in arrays and describe things with object properties.

14 min 5-question quiz 1 code exercise
By the end of this lesson you can
  • Create and index an array
  • Loop through array values
  • Read properties from an object

An array stores an ordered list. Its first item is at index 0. An object groups named properties that describe one thing.

student.js
1const student = {
2  name: "Ada",
3  scores: [90, 100, 95],
4};
5
6console.log(student.name);
7console.log(student.scores[0]);
Output
Ada
90

Use a dot to read a property such as student.name, and square brackets with an index to read an array item such as scores[0]. Arrays also have useful methods like map, filter and reduce.

Key takeaways

  • Arrays are ordered and start at index 0.

  • Objects store named properties.

  • Use dot notation for a property and brackets for an index.

Lesson quiz

5 questions · pass with 4 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write JavaScript

Write the program, run it against the test cases, and use the feedback to build your JavaScript skills.

Exercise 1

Student summary

+25 XP

The input is JSON for a student with a name and a scores array. Print the name, a colon, and the average score.

  • Three scores
  • Two scores
main.js
Loading editor…

JavaScript runs in a sandboxed browser frame with a 1.5 second time limit. Input is available as the string variable input.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…

Did you like the lesson? 😆👍
Consider a donation to support our work: