Skip to content
Advertisement

Check if variable is a Response object or normal object

Is it possible to check if a variable is a Resonse type object vs a normal object?

I have tried to use typeof, but both cases end in the object. I also tried to do Object.keys(myVar). This gives me an empty array on Response and keys on the object. This could work, but I hope there is a better way to distinguish both.

JavaScript

Advertisement

Answer

You can use the instanceOf operator for this purpose:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement