Object Methods in JavaScript

Level 3108 keystrokes

This uses Object.keys and Object.values to get an object's keys and values.

JavaScript code

// Create an object with name and age properties
1let person = {
2 name: "Tom",
3 age: 30
4};
// Object.keys() returns an array of property names
// Returns ["name", "age"]
5console.log(Object.keys(person));
// Object.values() returns an array of property values
// Returns ["Tom", 30]
6console.log(Object.values(person));

Output

[ 'name', 'age' ]
[ 'Tom', 30 ]
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • .× 4
  • (× 4
  • )× 4
  • ;× 3
  • :× 2
  • "× 2
  • ,× 1
  • {× 1
  • }× 1
  • =× 1

More JavaScript examples at level 3

← JavaScript typing practice