How to check Object is empty or not in JS?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello dev’s
Hope all are feeling good and okay . Today in this tutorial I will show How to check Object is empty or not in js . Now you can easily check that your JavaScript OR jQuery code object is empty or not. Because we need to check many place our application that jQuery object is empty or not, null or undefined etc. So usually, we can easily check by using $.isEmptyObject() as i explained it under.

Read Also : Angularjs PHP MySQL Pagination Example

How to check empty object in our Jquery. Now we show how to check empty object in jquery by using jQuery.isEmptyObject() example, jquery check object is null, jquery check object is empty, jquery check object is empty or not, how to check json objects are empty or not by using jquery, also  can check if json objects are empty or not by using jquery

if($.isEmptyObject(your_object)){
   alert("This Object is empty.");
}else{
  alert("This Object is not empty.");
}

Read Also : Angular Bubble Chart Example Tutorial

We can also check it by other way to our object is empty or not. I also describe under.

if (your_object && your_object instanceof Array && !your_object.length) {
   console.log('This Object is empty.');
} else {
   console.log('This Object is not empty.');
}

Read Also : PHP AngularJS CRUD with Search and Pagination Example From Scratch

Now you can try this.Hope it will help you. Also you can follow us on Facebook .

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →