Objects – Methods (keys, values, entries), online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
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
What students will learn in this module
Every question in Module 33
Quick questions
- Does Object.keys() return an array of an object's keys?ANoBYes
- Does Object.values() return an array of an object's values?ANoBYes
- Does Object.entries() return an array of key-value pairs?AYesBNo
- Is 'object' with a lowercase o valid for these methods?ANoBYes
- 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 doesObject.values(person)Match it to what it doesReturns an array pairing each key with its valueMatch it to what it doesCollects only the property names of an objectMatch it to what it doesconsole.log(object.keys(a));Match it to what it doesconsole.log(Object.Keys(b));Match it to what it doesFill in the blanks
console.log(Object.____(person));
Hint: Type the method that returns an object's keys.
console.log(Object.______(person));
Hint: Type the method that returns an object's values.
console.log(Object._______(person));
Hint: Type the method that returns an object's key-value pairs.
let names = Object.____(car);
Hint: Type the method that returns an object's keys.
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);
