Home > Web Front-end > JS Tutorial > How jquery determines whether it is an array

How jquery determines whether it is an array

coldplay.xixi
Release: 2020-11-17 10:25:36
Original
2287 people have browsed it

Jquery method to determine whether it is an array: Use the isArray method to determine whether a variable is an array type. The return value is a Boolean type, and the code is [var bool1 = $.isArray(obj)].

How jquery determines whether it is an array

Recommendation: "jquery video tutorial"

Jquery method to determine whether it is an array:

jquery provides the isArray method to determine whether a variable is an array type, and the return value is Boolean type.

Example:

var obj = {a:1};
var arr = [1, 2];
var bool1 = $.isArray(obj); 
var bool2 = $.isArray(arr);
console.log(bool1); //false
console.log(bool2); //true
Copy after login

Native js method to determine whether it is an array:

[] instanceof Array  // true
[].constructor == Array  // true
Object.prototype.toString.call([]) == '[object Array]'  // true
Copy after login

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How jquery determines 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