Reputation: 2534
I have an error object, I have printed it using the code: console.log(error);
The console printed value is:
SigninError {id: "el-20003", description: ""}
I need to get the "SigninError" as string. How to get that?
Upvotes: 0
Views: 49
Reputation: 4830
That string is probably the class name of the object. You can get it like so:
console.log(error.constructor.name)
Note: This may or may not work for you depending on how the Error object class was instantiated and whether or not you use a destructive minifier or a code mangler.
Upvotes: 2
Reputation: 30739
Use Object.keys(error)
to get the keys of error
object as an array and then use toString()
to change it to string value:
let error = {
SigninError:{id: "el-20003", description: ""}
}
var keys = Object.keys(error);
console.log(keys.toString());
Upvotes: 1