Javascript Object methods every developer should know

let obj = {}; = “messi”;
obj.year= 2018;
obj.speak = function(){
 return “My Name is “” and this is year “+this.year;

Deep Copy

If you just need to copy only properties which are not functions — there is an efficient method. We are moving away from Object constructor here and using another global Object in JS — JSON

let deepCopyObj = JSON.parse(JSON.stringify(obj));
//{ name: 'messi', year: 2019 }


You can also create object with Object.create() function this has additional flexibility that you can choose what will be prototype of your new object.

let createObj = Object.create(obj);
console.log(createObj);  //{} = “Pk”;
// My Name is Pk and this is year 2019