Link to home
Start Free TrialLog in
Avatar of Zolf
ZolfFlag for United Arab Emirates

asked on

Angular - Check JSON object is empty or not

Hi there,

I want to check if the JSON object returned from server is empty or not. I tried something like this but it does not work

 if(response)
 {
        console.log("response", response);
 }
else
{
         console.log("response Empty");
}


Open in new window

The response looks like so,
SERVER RESPONSE: {}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

Try this.
if (Object.keys(response).length) {
  console.log("response", response);
}
else {
  console.log("response Empty");
}

Open in new window

Avatar of Zolf

ASKER

Norie 
Appreciate your help, just saw your message. leakim971 suggestion worked as expected.