Home  >  Article  >  Web Front-end  >  How to determine whether an object is empty in jquery

How to determine whether an object is empty in jquery

王林
王林Original
2020-11-24 15:08:163689browse

Jquery method to determine whether an object is empty: You can determine based on the length attribute of the dom object, such as [obj.length == 0]. If it is a custom object, you can use the isEmptyObject method to judge.

How to determine whether an object is empty in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version. This method is suitable for all brands of computers.

(Learning video sharing: javascript video tutorial)

Jquery method to determine whether the object is empty:

1. There are two types of jquery objects, one is the dom object, the dom object will have its own length attribute, so in this case:

obj.length == 0

can determine that the object is empty

2, jquery can also Custom objects, such as var obj = {}. In this case, the object defined will not have a length attribute, so you need to use the jquery method: $.isEmptyObject()

if($.isEmptyObject(obj) == true){
    console.log("对象为空");
  }else{
    console.log("对象非空");
  }

Related recommendations: js tutorial

The above is the detailed content of How to determine whether an object is empty in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does jquery mean?Next article:What does jquery mean?