Skip to content

Instantly share code, notes, and snippets.

@MateusAndrade
Last active February 2, 2019 23:59
Show Gist options
  • Save MateusAndrade/bf904e6cc2cfa78f7d1f114a4546e426 to your computer and use it in GitHub Desktop.
Save MateusAndrade/bf904e6cc2cfa78f7d1f114a4546e426 to your computer and use it in GitHub Desktop.
Returns all object propertys using this scope in a ES6 class parsed to a JSON
toJson(){
let _obj: any = {};
let _str:string = "";
for (const key in this) {
if (this.hasOwnProperty(key)) {
_str = key;
_str = _str.replace(_str.charAt(0),"");
_obj[_str] = this["_"+_str];
}
}
return JSON.stringify(_obj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment