Widely availableImportant background knowledge, though object literals are usually the clearest way to create plain objects in application code.

Overview

The Object constructor and related static methods define the basic behavior of plain object values. Understanding them helps when creating records, inspecting properties, and controlling prototypes.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
1
18
1

The Object() constructor turns the input into an object. Its behavior depends on the input's type.

1
12
1
1
18
1

The Object.assign() static method copies all Object/propertyIsEnumerable Object/hasOwn from one or more source objects to a target object. It returns the modified target object.

45
12
34
9
45
9

The constructor data property of an Object instance returns a reference to the constructor function that created the instance object. Note that the value of this property is a reference to the function itself, not a string containing the function's name.

1
12
1
1
18
1

The Object.create() static method creates a new object, using an existing object as the prototype of the newly created object.

5
12
4
5
18
5

The Object.defineProperties() static method defines new or modifies existing properties directly on an object, returning the object.

5
12
4
5
18
5

The Object.defineProperty() static method defines a new property directly on an object, or modifies an existing property on an object, and returns the object.

5
12
4
5.1
18
6

The Object.entries() static method returns an array of a given object's own enumerable string-keyed property key-value pairs.

54
14
47
10.1
54
10.3

The Object.freeze() static method freezes an object. Freezing an object prevents extensions and makes existing properties non-writable and non-configurable. A frozen object can no longer be changed: new properties cannot be added, existing properties cannot be removed, their enumerability, configurability, writability, or value cannot be changed, and the…

6
12
4
5.1
18
5

The Object.fromEntries() static method transforms a list of key-value pairs into an object.

73
79
63
12.1
73
12.2

The Object.getOwnPropertyDescriptor() static method returns an object describing the configuration of a specific property on a given object (that is, one directly present on an object and not in the object's prototype chain). The object returned is mutable but mutating it has no effect on the original property's configuration.

5
12
4
5
18
5

The Object.getOwnPropertyDescriptors() static method returns all own property descriptors of a given object.

54
15
50
10
54
10

The Object.getOwnPropertyNames() static method returns an array of all properties (including non-enumerable properties except for those which use Symbol) found directly in a given object.

5
12
4
5
18
5

The Object.getOwnPropertySymbols() static method returns an array of all symbol properties found directly upon a given object.

38
12
36
9
38
9

The Object.getPrototypeOf() static method returns the prototype (i.e., the value of the internal [[Prototype]] property) of the specified object.

5
12
3.5
5
18
5

The hasOwnProperty() method of Object instances returns a boolean indicating whether this object has the specified property as its own property (as opposed to inheriting it).

1
12
1
3
18
1

The Object.is() static method determines whether two values are the same value.

19
12
22
9
25
9

The Object.isExtensible() static method determines if an object is extensible (whether it can have new properties added to it).

6
12
4
5.1
18
5

The Object.isFrozen() static method determines if an object is Object/freeze.

6
12
4
5.1
18
5

The isPrototypeOf() method of Object instances checks if this object exists in another object's prototype chain.

1
12
1
3
18
1

The Object.isSealed() static method determines if an object is sealed.

6
12
4
5.1
18
5

The Object.keys() static method returns an array of a given object's own enumerable string-keyed property names.

5
12
4
5
18
5

The Object.preventExtensions() static method prevents new properties from ever being added to an object (i.e., prevents future extensions to the object). It also prevents the object's prototype from being re-assigned.

6
12
4
5.1
18
5
Object.preventExtensions.ES2015 behavior

ES2015 behavior for non-object argument

44
12
35
9
44
9

The propertyIsEnumerable() method of Object instances returns a boolean indicating whether the specified property is this object's enumerable own property.

1
12
1
3
18
1

The Object.seal() static method seals an object. Sealing an object prevents extensions and makes existing properties non-configurable. A sealed object has a fixed set of properties: new properties cannot be added, existing properties cannot be removed, their enumerability and configurability cannot be changed, and its prototype cannot be re-assigned. Values…

6
12
4
5.1
18
5

The Object.setPrototypeOf() static method sets the prototype (i.e., the internal [[Prototype]] property) of a specified object to another object or null.

34
12
31
9
34
9

The toString() method of Object instances returns a string representing this object. This method is meant to be overridden by derived objects for custom type coercion logic.

1
12
1
1
18
1

The valueOf() method of Object instances converts the this value to an object. This method is meant to be overridden by derived objects for custom type conversion logic.

1
12
1
1
18
1

The Object.values() static method returns an array of a given object's own enumerable string-keyed property values.

54
14
47
10.1
54
10.3
Other
javascript.grammar.shorthand_object_literals

Shorthand notation for object literals

43
12
33
9
43
9

An object initializer is a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). Objects can also be initialized using Object.create() or by invoking a constructor function with the new operator.

1
12
1
1
18
1
Operator
computed property names

Computed property names

47
12
34
8
47
8
shorthand method names

Shorthand method names

47
12
34
9
47
9
shorthand property names

Shorthand property names

47
12
33
9
47
9
spread properties

Spread properties

60
79
55
11.1
60
11.3
Other

The optional chaining (?.) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null, the expression short circuits and evaluates to undefined instead of throwing an error.

80
80
74
13.1
80
13.4
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Implementation note
  • Also supported in Safari 5, but not on DOM objects.
Notes 1 item(s)
Implementation note
  • Also supported in Safari for iOS 4.2, but not on DOM objects.

Syntax

JAVASCRIPT
// Merge
const merged = Object.assign({}, { a: 1 }, { b: 2 });

// Freeze
const frozen = Object.freeze({ x: 1 });
// frozen.x = 2; // Throws an error in strict mode

// Define a property
Object.defineProperty(obj, 'prop', {
  value: 42,
  writable: false
});

Live demo

Object.fromEntries

[key, value] pea from object generate.Object.entries. reverse.

PreviewFullscreen

Object. Convert

Object convert. with entries + map + fromEntries

PreviewFullscreen

Object.groupBy

Array property in groupizationobject to convert.

PreviewFullscreen

Use cases

  • Creating simple records

    Plain objects remain useful for fixed-key data such as settings, summaries, and lightweight DTOs.

  • Inspecting property behavior

    Object methods help enumerate, freeze, seal, and examine the shape of runtime data.

Cautions

  • Object as a dictionary has historical edge cases around prototypes; Map is often a better fit for arbitrary keys.
  • Prototype-related APIs are powerful but can make code harder to reason about when overused.

Accessibility

  • Stable object shapes can make UI state handling more predictable, which reduces hard-to-debug accessibility regressions.

Powered by web-features