← JavaScript

Objects – Methods (keys, values, entries)

Returns an array containing all the keys of a given object.

Understanding Objects – Methods (keys, values, entries) in JavaScript

What it does: 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(). Object.keys(), values(), and entries() all need an object to inspect. The method name must be lowercase: keys(). JavaScript's built-in is Object, not object.

Common mistakes: 'Object' must start with a capital O, not lowercase. 'keys' must be lowercase - a capital K causes an error.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 31–40) and word search (Modules 21–52).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Does Object.keys() return an array of an object's keys?
YesNo
Matches
console.log(object.keys(a));
↓
Wrong - 'Object' must start with a capital O
Applying
Meanings
Term
Object.keys()
Meaning
Returns an array containing all the keys of a given object.
Practice
let person = {name: "Sam", age: 12};
Testing
Gaps
console.log(Object.(person));
Check Answer
Spots
1console.log(object.keys(a));
2let a = {x: 1};

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Pufferfish' badge — Error Handler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Does Object.keys() return an array of an object's keys?
A. No
B. Yes ✓
Object.keys() collects every key from the object into an array.
2. Does Object.values() return an array of an object's values?
A. No
B. Yes ✓
Object.values() collects every value from the object into an array.
3. Does Object.entries() return an array of key-value pairs?
A. Yes ✓
B. No
Object.entries() pairs each key with its value in the array.
4. Is 'object' with a lowercase o valid for these methods?
A. No ✓
B. Yes
JavaScript requires a capital O: Object.keys().
5. Do these methods need an object passed as an argument?
A. Yes ✓
B. No
Object.keys(), values(), and entries() all need an object to inspect.

Match the Pairs

Object.keys(person) → Returns an array of person's keys
Object.values(person) → Returns an array of person's values
Returns an array pairing each key with its value → Object.entries(person)
Collects only the property names of an object → Object.keys(car)
console.log(object.keys(a)); → Wrong - 'Object' must start with a capital O
console.log(Object.Keys(b)); → Wrong - 'keys' must start with a lowercase k

Key Term

Object.keys()
Returns an array containing all the keys of a given object.

Fill in the Blanks

1. console.log(Object.keys(person));
Hint: Type the method that returns an object's keys.
2. console.log(Object.values(person));
Hint: Type the method that returns an object's values.
3. console.log(Object.entries(person));
Hint: Type the method that returns an object's key-value pairs.
4. let names = Object.keys(car);
Hint: Type the method that returns an object's keys.
5. let vals = Object.values(car);
Hint: Type the method that returns an object's values.

Spot the Error

Question 1
A console.log(object.keys(a));
B let a = {x: 1};
C console.log(a);
Line A — 'Object' must start with a capital O, not lowercase.
Question 2
A let b = {y: 2};
B console.log(Object.Keys(b));
C console.log(b);
Line B — 'keys' must be lowercase - a capital K causes an error.
Question 3
A let c = {z: 3};
B console.log(c);
C console.log(Object.values(c));
Line C — This line is actually correct - Object.values() works this way.
Question 4
A console.log(Object.Values(d));
B let d = {a: 1};
C console.log(d);
Line A — 'values' must be lowercase - a capital V causes an error.
Question 5
A let e = {b: 2};
B console.log(Object.entries(e));
C console.log(e);
Line B — This line is actually correct - Object.entries() works this way.

Student with a class code? Join your class →