JavaScript Object Functions cheatsheet
Object.defineProperties()
Object.defineProperties() defines new or modifies existing properties
Syntax
Object.defineProperties(obj, props)
Example
Object.defineProperties({ a: 10, b: 20 }, { a: {
value: 30,
writable: true,
}}) // { a: 30, b: 20 }
Object.assign()
Object.assign() is a method which copies properties from one or more source object to a target object.
Syntax
Object.assign(target, ...sources)
Example
Object.assign({ a: 10, b: 20 }, { c: 30 }, { d: 40 })
// { a: 10, b: 20, c: 30, d: 40 }
Object.entries()
Object.entries() returns array of object's [key, value] pairs.
Syntax
Object.entries(obj)
Example
Object.entries({ a: 1, b: 2 })
// [ ["a", 1], ["b", 2] ]
Object.defineProperty()
Object.defineProperty() defines new or modifies existing property.
Syntax
Object.defineProperty(obj, prop, descriptor)
Example
Object.defineProperty({ a: 1, b: 2 }, 'a', {
value: 3,
writable: true
}); // { a: 3, b: 2 }
Object.create()
Object.create() creates a new object, using an existing object as the prototype.
Syntax
Object.create(proto, [propertiesObject])
Example
Object.create({ a: 2 })
// <prototype>: Object { a: 2 }
0 Comments
If you have any question please ask?