jQuery.type()Method

jQuery 杂项方法jQuery Miscellaneous Methods

Example

Whether the parameter is a regular expression

Is this a regular expression? <b></b> <script> $(function () { $( "b" ).append( "" + jQuery.type( /test/ ) ); }) </script>

Try it yourself »

Definition and Usage

The $.type() function is used to determine the type of JavaScript built-in objects, 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 the object has an internal property [[Class]] that is the same as the [[Class]] 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 needs to be determined.


jQuery 杂项方法jQuery Miscellaneous Methods

Other Extensions