Home > Web Front-end > JS Tutorial > body text

How to determine whether an object is empty in jquery

coldplay.xixi
Release: 2023-01-04 09:37:53
Original
4685 people have browsed it

Jquery method to determine whether an object is empty: 1. Use the dom object to determine if it is zero. If it is zero, it is empty, and the code is [obj.length == 0]; 2. Use a custom object to determine, the code is [ $.isEmptyObject()].

How to determine whether an object is empty in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

Recommended: jquery video tutorial

Jquery method to determine whether an object is empty:

1. One It is a dom object

The dom object will have a length attribute, so in this case:

  obj.length == 0
Copy after login

You can judge that the object is empty

2. One is a custom object

such as var obj = {}. In this case, the object defined will not have a length attribute.

You need to use the jquery method: $ .isEmptyObject()

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

Related free learning recommendations: javascript video 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!