JS: Access Property, List Properties

By Xah Lee. Date: . Last updated: .

This page shows all the ways to work with properties.

Get Property

Get Property
syntaxmeaninguse proto chainwork with symbol key
o[k] Return the value of the property. yesyes
Reflect.get (o,k) Return the value of the property. [see JS: Reflect.get] yesyes

[see JS: Symbol Tutorial]

Set Property

Set Property
syntaxmeaninguse proto chainwork with symbol key
o[k] = v Modify or create a new property for the object. noyes
Reflect.set (o, k, v) Modify or create a new property for the object. [see JS: Reflect.set] noyes

Delete Property

Delete Property
syntaxmeaninguse proto chainwork with symbol key
delete o[k] Returns true, even if property does not exist. [see JS: Delete operator] noyes
Reflect.deleteProperty (o,k) Returns true, if delete is successful. [see JS: Reflect.deleteProperty] noyes

Check Property Existence

Check Property Existence
syntaxmeaninguse proto chainwork with symbol key
o.hasOwnProperty(k) true if the object has the property. [see JS: Object.prototype.hasOwnProperty] noyes
k in o
or
Reflect.has (o,k)
true if is own property or in prototype chain. [see JS: Reflect.has] yesyes

Loop-Thru (Enumerate) Properties

Loop Over Properties or Values
syntaxmeaningproto chainenumerable onlyinclude symbol keyinclude string key
for (let k in o) {…} [see JS: for-in Loop] yesyesnoyes
for (let v of iterable) {…} loop thru values of iterable object iterable. [see JS: for-of Loop] N/AN/AN/AN/A

List Properties

To list properties, convert the object to array.

[see JS: List Properties]

JS Object Property Topic

  1. JS: Property Overview
  2. JS: Property Key
  3. JS: Property Dot Notation / Bracket Notation
  4. JS: Create/Delete Property
  5. JS: Get Property, Set Property
  6. JS: Check Property Existence
  7. JS: Access Property, List Properties
  8. JS: Property Attributes
  9. JS: Getter/Setter Properties
  10. JS: Property Descriptor
Liket it? Put $1 at patreon.

Or, Buy JavaScript in Depth