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

How jquery determines whether it is an array

coldplay.xixi
coldplay.xixiOriginal
2020-11-17 10:25:362237browse

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

Native js method to determine whether it is an array:

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

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!

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