— by Abhisek Pattnaik <[email protected]>
Last active
March 16, 2018 02:55
-
-
Save abhisekp/8adc974baa13c42a859d5c1a214ab256 to your computer and use it in GitHub Desktop.
Object Property Assignment in JavaScript — http://bit.ly/js-obj
-
Using Dot Notation
const student = { name: 'Abhisek' }; student.age = 109; // dot operator assigment
-
Using Bracket Notation
const student = { name: 'Abhisek' }; student['age'] = 150; // bracket assignment
-
Using Object Spread
let student = { name: 'Abhisek' }; student = { ...student, // object spread age: 200 } //➔ {name: 'Abhisek', age: 300}
-
Using
Object.assign
const student = { name: 'Abhisek' }; Object.assign(student, { age: 300 }); //➔ {name: 'Abhisek', age: 300}
-
Using
Object.defineProperty
const student = { name: 'Abhisek' }; Object.defineProperty(student, 'age', { value: 400, writable: true, configurable: true, enumerable: true }); //➔ {name: 'Abhisek', age: 300}
-
Using
Reflect.defineProperty
const student = { name: 'Abhisek' }; Reflect.defineProperty(student, 'age', { value: 600, writable: true, configurable: true, enumerable: true }); //➔ true
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment