Home >Web Front-end >JS Tutorial >How to determine if an object is empty in jquery

How to determine if an object is empty in jquery

coldplay.xixi
coldplay.xixiOriginal
2020-11-26 14:45:162360browse

Jquery method to determine whether an object is empty: 1. Use the length attribute of the dom object to determine, the code is [obj.length == 0]; 2. Use the custom object method to determine, the code is [$. isEmptyObject()].

How to determine if an object is empty in jquery

  • This method is suitable for all brands of computers

jquery Method to determine whether the object is empty:

One is the dom object

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

obj.length == 0

You can judge that the object is empty

The other is a custom object

such asvar obj={}, this Objects defined by a case will not have a length property.

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

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

Related free learning recommendations: javascript(Video)

The above is the detailed content of How to determine if 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