I am using the Object
class of JavaScript to check if a variable exists before using it from a JSON response.
When I try to call that line of code I get this error
Cannot convert undefined or null to object
at Function.keys ()
at successCallback
Here is my attempt:
if (Object.keys(response.data.data.user_fk)) {
$rootScope.username = response.data.data.user_fk.name;
}
Please how can I get the check right?