[Cheat Sheet ] JavaScript Object Functions Part 1



JavaScript Object Functions cheatsheet

Object.defineProperties()

Object.defineProperties() defines new or modifies existing properties

Syntax


    Object.defineProperties(objprops)

Example






    Object.defineProperties({ a10b20 }, { a: {
      value30,
      writabletrue,
    }}) // { 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({ a10b20 }, { c30 }, { d40 }) 
    // { 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({ a1b2 }) 
    // [ ["a", 1], ["b", 2] ]


Object.defineProperty()

Object.defineProperty() defines new or modifies existing property.

Syntax


    Object.defineProperty(objpropdescriptor)


Example


    Object.defineProperty({ a1b2 }, 'a', {
      value3,
      writabletrue
    }); // { 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({ a2 }) 
    // <prototype>: Object { a: 2 }












Recommend

Reactions

Post a Comment

0 Comments