javascript - How to set a lot a class properties from an object with the same property names? -
i'm working in js , i've got following object lot of properties:
var foo = { prop1: 123, prop2: 456, prop3: 789, ... propx: 321 }
i want set class same properties.
i can that:
this.prop1 = foo.prop1 this.prop2 = foo.prop2 this.prop2 = foo.prop2 ... this.propx = foo.propx
but i'm looking like:
for(var property in foo) { this.[property] = foo[property] }
do know if it's possible kind of behavior in js?
i'd set class properties single loop for.
check if this
has property , assign foo
for(var property in foo) { if(this.hasownproperty(property)) { this[property] = foo[property]; } }
or better way loop keys in this
, not need if
statement.
Comments
Post a Comment