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

How does jquery determine whether it is an array?

青灯夜游
Release: 2020-11-30 11:58:13
Original
2488 people have browsed it

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
Copy after login

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
Copy after login

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 这两段代码是一样的
Copy after login

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!

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