Home  >  Article  >  Web Front-end  >  How does jquery determine whether it is an array?

How does jquery determine whether it is an array?

青灯夜游
青灯夜游Original
2020-11-24 11:13:522392browse

Jquery method to determine whether it is an array: use the [$.isArray()] function, which can determine whether the specified parameter is an array, the syntax format is [$.isArray(object)]; if the parameter object is specified If it is an array, it returns true, otherwise it returns false.

How does jquery determine whether it is an array?

Related recommendations: "jQuery Video Tutorial"

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

Jquery method to determine whether it is an array:

Use isArray() to determine whether it is an array

JQuery has encapsulated isArray() to determine whether it is an array

$.isArray()The function is used to determine whether the specified parameter is an array; if the specified parameter is an array, it returns true, otherwise false is returned.

var arr = [1,3];
var bool = $.isArray(arr);//判断是否为数组  返回Boolean
console.log(bool); //true

How does jquery determine whether it is an array?

Supplement:js judgment method

instanceof judgment

var ary = [1,23,4];
console.log(ary instanceof Array);  //true

How does jquery determine whether it is an array?

Prototype chain method judgment

var ary = [1,23,4];
console.log(ary.__proto__.constructor==Array);//true
console.log(ary.constructor==Array);//true 这两段代码是一样的

For more programming-related knowledge, please visit: Programming video course! !

The above is the detailed content of How does jquery determine whether it is an array?. 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