Objects – Methods (keys, values, entries), online

Six activities your students do on their own devices. See who's finished, and their scores.

Objects – Methods (keys, values, entries) in one minute

What students need to know

Object.entries() gives back an array of [key, value] pairs. keys() returns just the names of the object's properties.

Object.keys() collects every key from the object into an array. JavaScript requires a capital O: Object.keys().

Mistakes students make

  • 'Object' must start with a capital O, not lowercase.
  • 'keys' must be lowercase - a capital K causes an error.
  • This line is actually correct - Object.values() works this way.
  • 'values' must be lowercase - a capital V causes an error.
PREVIOUS · MODULE 32Objects – Creation and Access
YOU ARE HERE · MODULE 33Objects – Methods (keys, values, entries)
NEXT · MODULE 34Objects – for...in Loop

Discover other journeys with this module

What students will learn in this module

Every question in Module 33

Quick questions

  1. Does Object.keys() return an array of an object's keys?ANoBYes
  2. Does Object.values() return an array of an object's values?ANoBYes
  3. Does Object.entries() return an array of key-value pairs?AYesBNo
  4. Is 'object' with a lowercase o valid for these methods?ANoBYes
  5. Do these methods need an object passed as an argument?AYesBNo

Key terms

Students type the meaning of:

  • Object.keys()

Match the pairs

Object.keys(person)Match it to what it does
Object.values(person)Match it to what it does
Returns an array pairing each key with its valueMatch it to what it does
Collects only the property names of an objectMatch it to what it does
console.log(object.keys(a));Match it to what it does
console.log(Object.Keys(b));Match it to what it does

Fill in the blanks

  1. console.log(Object.____(person));

    Hint: Type the method that returns an object's keys.

  2. console.log(Object.______(person));

    Hint: Type the method that returns an object's values.

  3. console.log(Object._______(person));

    Hint: Type the method that returns an object's key-value pairs.

  4. let names = Object.____(car);

    Hint: Type the method that returns an object's keys.

  5. let vals = Object.______(car);

    Hint: Type the method that returns an object's values.

Spot the error

Question 1

Aconsole.log(object.keys(a));Blet a = {x: 1};Cconsole.log(a);

Question 2

Alet b = {y: 2};Bconsole.log(Object.Keys(b));Cconsole.log(b);

Question 3

Alet c = {z: 3};Bconsole.log(c);Cconsole.log(Object.values(c));

Question 4

Aconsole.log(Object.Values(d));Blet d = {a: 1};Cconsole.log(d);

Question 5

Alet e = {b: 2};Bconsole.log(Object.entries(e));Cconsole.log(e);