JavaScript AcademyProfessional Engineering

Learning object 24 of 100

Object property inspector

Type an object and see every key, value and type, what Object.keys, values and entries return, and how a key lookup behaves.

Loading…

What it shows

An object is a set of key-value properties. Object.keys, Object.values and Object.entries turn it into arrays you can loop over. Reading a missing key gives undefined. The in operator also finds inherited properties such as toString, so use Object.hasOwn when checking data.

Guided experiment

  1. Look up "email". What does reading a missing key give?
  2. Look up "toString". Why is in true but hasOwn false?
  3. Inspect { 2: "b", 1: "a", z: "last" }. What order are the keys in?

Predict

What does Object.keys({ a: 1, b: 2 }) return?

Related

Lessons: Lesson 36: Creating JavaScript objects, Lesson 37: Properties, methods and dynamic keys

Projects: Project 9: Shopping Cart Price Calculator

Source: web/assets/js/objects/object-024.js in the companion repository.