Home  >  Article  >  Web Front-end  >  How to determine whether jquery is an array

How to determine whether jquery is an array

青灯夜游
青灯夜游Original
2021-01-06 16:37:073251browse

In jquery, you can use the "$.isArray()" function to determine whether the specified parameter is an array. The syntax is "$.isArray(object)". The parameter object represents any type that needs to be judged. Value; returns true if the specified parameter is an array, false otherwise.

How to determine whether jquery is an array

The operating environment of this tutorial: windows7 system, jquery3.5 version, Dell G3 computer.

Recommended tutorial: jQuery tutorial

isArray() function detailed explanation

$.isArray() function is used to determine the specified Whether the parameter is an array.

This function belongs to the global jQuery object.

Syntax:

$.isArray( object )

Parameters:

object: Any type Any value that needs to be judged.

Return value:

Boolean type, if the specified parameter is an array, it returns true, otherwise it returns false.

Example:

//在当前页面内追加换行标签和指定的HTML内容
function w( html ){
	document.body.innerHTML += "<br/>" + html;
}



w( $.isArray( [ 10, 25, 3 ] ) ); // true
w( $.isArray( new Array() ) ); // true


w( $.isArray( null ) ); // false
w( $.isArray( true ) ); // false
w( $.isArray( { } ) ); // false

var obj = { };
obj[0] = 10;
obj[1] = 25;
obj[2] = 3;
obj.length = 3;
// obj是一个类数组对象,但它仍然不是一个真正的数组
w( $.isArray( obj ) ); // false

Output:

true
true
false
false
false
false

For more programming related knowledge, please visit:Programming Teaching! !

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