0
0
Javascriptprogramming~5 mins

Object keys and values in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are object keys in JavaScript?
Object keys are the names or identifiers used to access values stored in an object. They are always strings or symbols.
Click to reveal answer
beginner
How do you get all keys of an object in JavaScript?
You use Object.keys(yourObject) to get an array of all keys in the object.
Click to reveal answer
beginner
What does Object.values(obj) return?
It returns an array containing all the values of the object's own enumerable properties.
Click to reveal answer
intermediate
Can object keys be numbers in JavaScript?
No, object keys are always strings or symbols. If you use a number, JavaScript converts it to a string.
Click to reveal answer
intermediate
How can you loop through all keys and values of an object?
You can use a for...in loop to go through keys, then access values with obj[key]. Or use Object.entries(obj) to get key-value pairs.
Click to reveal answer
Which method returns an array of an object's keys?
AObject.values()
BObject.keys()
CObject.entries()
DObject.getOwnPropertyNames()
What type are object keys in JavaScript?
AOnly numbers
BAny data type
CBooleans
DStrings or symbols
What does Object.values(obj) return?
AAn array of values
BAn array of keys
CAn array of key-value pairs
DThe object itself
How can you get both keys and values together from an object?
AObject.entries()
BObject.values()
CObject.keys()
DObject.getOwnPropertyDescriptors()
What happens if you use a number as an object key?
AIt stays a number key
BIt causes an error
CIt becomes a string key
DIt becomes a boolean key
Explain how to retrieve all keys and values from a JavaScript object.
Think about methods that return arrays representing keys, values, or both.
You got /4 concepts.
    Describe what types object keys can be and what happens if you use a number as a key.
    Consider how JavaScript treats keys internally.
    You got /3 concepts.