Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery.type() Method

The jQuery.type() method

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods

Example

Whether the argument is a regular expression

Is this a regular expression? <

b

b

<script$(function(){$("b" )>

.

append

(

"

"

jQuery

.

type

(

/

test

/

)

)

;

}

)

script

Try it »


Definition and Usage

The $.type() function is used to determine the type of a JavaScript built-in object and returns the type name in lowercase.

If the object is undefined or null, the corresponding "undefined" or "null" is returned



$.type( undefined ) === "undefined"



$.type() === "undefined"



$.type( window.notDefined ) === "undefined"



$.type( null ) === "null"

If an object has an internal [[Class]] property that is the same as that of a browser's built-in object, we return the corresponding [[Class]] name.



$.type( true ) === "boolean"



$.type( 3 ) === "number"



$.type( "test" ) === "string"



$.type( function(){} ) === "function"



$.type( [] ) === "array"



$.type( new Date() ) === "date"



$.type( new Error() ) === "error" // jQuery 1.9 新增支持



$.type( /test/ ) === "regexp"

Syntax

$

.type( obj )

Parameters Description
obj Any type: Any object whose type is to be determined.

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods