Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (47.6k points)

After an AJAX request, sometimes my application may return an empty object, like:

var a = {};

How can I check whether that's the case?

1 Answer

0 votes
by (106k points)
edited by

Below are some steps to test for an empty JavaScript object:- 

For ECMA version 7+ you can use the following code:-

Object.entries(obj).length === 0 && obj.constructor === Object

For ECMA version 5+ use following code:

Object.keys(obj).length === 0 && obj.constructor === Object

Want to become a Web Developer, here's a Web Development Courses for you!

Related questions

0 votes
1 answer
0 votes
0 answers
0 votes
1 answer
asked Jan 27, 2021 in Java by dante07 (13.1k points)
0 votes
0 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories