bhylu.com

Advertisements

Object Properties

Bracket notation lets a property name come from a variable. Use it for names chosen at runtime.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const session = {title: "Repair club", places: 12};
const field = "places";
console.log(session[field]);

What happens

The chosen property gives 12.