copies properties from one or more source objects to target object Object.assign({ a: 1, b: 2 }, { c: 3 }, { d: 4 }) // { a: 1, b: 2, c: 3, d: 4 }
Object.assign(target, ...sources)
creates new object, using an existing object as the prototype Object.create({ a: 1 }) // <prototype>: Object { a: 1 }
Object.create(proto, [propertiesObject])
defines new or modifies existing properties Object.defineProperties({ a: 1, b: 2 }, { a: {
value: 3,
writable: true,
}}) // { a: 3, b: 2 }
Object.defineProperties(obj, props)
defines new or modifies existing property Object.defineProperty({ a: 1, b: 2 }, 'a', {
value: 3,
writable: true
}); // { a: 3, b: 2 }
Object.defineProperty(obj, prop, descriptor)
returns array of object's [key, value] pairs Object.entries({ a: 1, b: 2 }) // [ ["a", 1], ["b", 2] ]
Object.entries(obj)
freezes an object, which then can no longer be changed const obj = { a: 1 }
Object.freeze(obj)
obj.prop = 2 // error in strict mode
console.log(obj.prop) // 1
transforms a list of key-value pairs into an object Object.fromEntries([['a', 1], ['b', 2]]) // { a: 1, b: 2 }
Object.fromEntries(iterable)
returns a property descriptor for an own property const obj = { a: 1 }
Object.getOwnPropertyDescriptor(obj, 'a') // { value: 1, writable: true, enumerable: true, configurable: true }
Object.getOwnPropertyDescriptor(obj, prop)
returns all own property descriptors const obj = { a: 1 }
Object.getOwnPropertyDescriptors(obj, 'a') // { a: { value: 1, writable: true, enumerable: true, configurable: true } }
Object.getOwnPropertyDescriptor(obj, prop)
returns array of all properties Object.getOwnPropertyNames({ a: 1, b: 2 }) // [ "a", "b" ]
Object.getOwnPropertyNames(obj)
array of all symbol properties const obj = { a: 1 }
const b = Symbol('b')
obj[b] = 'someSymbol' // obj = { a: 1, Symbol(b): "symbol" }
Object.getOwnPropertySymbols(obj) // [ Symbol(b) ]
Object.getOwnPropertySymbols(obj)
const proto = { a: 1 }
const obj = Object.create(proto)
obj.b = 2 // obj = { b: 2 }
Object.getPrototypeOf(obj) // { a: 1 }
Object.getPrototypeOf(obj)
determines whether two values are the same value const objA = { a: 1 }
const objB = { a: 1 }
Object.is(objA, objA) // true
Object.is(objA, objB) // false
Object.is('a', 'a') // true
Object.is(value1, value2)
determines wether an object can have new properties added to it const obj = {}
Object.isExtensible(obj) // true
Object.preventExtensions(obj)
Object.isExtensible(obj) // false
Object.isExtensible(obj)
determines if an object is frozen const obj = {}
Object.isFrozen(obj) // false
Object.freeze(obj)
Object.isFrozen(obj) // true
Object.isFrozen(obj)
determines if an object is sealed const obj = {}
Object.isSealed(obj) // false
Object.seal(obj)
Object.isSealed(obj) // true
Object.isSealed(obj)
returns array of object's enumerable property names Object.keys({ a: 1, b: 2 }) // [ "a", "b" ]
prevents new properties from being added to an object const obj = { a: 1 }
Object.preventExtensions(obj)
Object.defineProperty(obj, 'b', { value: 2 }) // Error: Can't define property "b": Object is not extensible
Object.preventExtensions(obj)
returns boolean indicating whether object has the specified property const obj = { a: 1 }
obj.hasOwnProperty('a') // true
obj.hasOwnProperty('b') // false
obj.hasOwnProperty(prop)
checks if object exists in another object's prototype chain const proto = { a: 1 }
const obj = Object.create(proto)
proto.isPrototypeOf(obj) // true
prototypeObj.isPrototypeOf(object)
checks whether the specified property is enumerable and is the object's own property const obj = { a: 1 }
const arr = ['a']
obj.propertyIsEnumerable('a') // true
arr.propertyIsEnumerable(0) // true
arr.propertyIsEnumerable('length') // false
obj.propertyIsEnumerable(prop)
returns a string representing the object const obj = {}
obj.toString() // "[object Object]"
const arr = ['a', 'b']
arr.toString() // "a,b"
prevents new properties from being added and marks all existing properties as non-configurable const obj = { a: 1 }
Object.seal(obj)
obj.a = 2 // { a: 2 }
obj.b = 3 // error in strict mode
delete obj.a // error in strict mode
returns array of object's own enumerable property values Object.values({ a: 1, b: 'a'}) // [ 1, "a" ]