Friday, 6 September 2013

Javascript native/elegant way to strip properties from object

Javascript native/elegant way to strip properties from object

I would like to know if there is a native/elegant way to do this:
var object = {
value: 1,
desc: 'an object',
method: function(){
return this.description + ' with value: ' + this.value;
},
};
var onlyProperties = JSON.parse(JSON.stringify(object));
As you can see I just want the properties without any methods in it. The
above code works but it feels wrong to do it this way.

No comments:

Post a Comment