JavaScript--To determine whether a data type

Source: Internet
Author: User

Why not use other methods, because the following wording takes into account various compatibility.
Determines whether an array
IsArray = function (source) {
Return ' [object Array] ' = = Object.prototype.toString.call (source);
};
Determines whether a Date object
IsDate = function (o) {
return o instanceof Date;
return {}.tostring.call (o) = = = "[Object Date]" && o.tostring ()!== ' Invalid Date ' &&!isnan (o);
};
Determines whether an element object
Iselement = function (source) {
Return!! (Source && source.nodename && Source.nodetype = = 1);
};
Determine if the target parameter is a function or function instance
Isfunction = function (source) {
Under Chrome, ' function ' = = typeof/a/is true.
Return ' [object Function] ' = = Object.prototype.toString.call (source);
};
Determines whether the target parameter is a number type or a number object
Isnumber = function (source) {
Return ' [object number] ' = = Object.prototype.toString.call (source) && isfinite (source);
};
Determines whether the target parameter is an object
IsObject = function (source) {
Return ' function ' = = typeof Source | | !! (Source && ' object ' = = = typeof source);
};
Determines whether the target parameter is a string type or a String object
isstring = function (source) {
Return ' [object String] ' = = Object.prototype.toString.call (source);
};
Determines whether the target parameter is a Boolean object
Isboolean = function (o) {
return typeof o = = = ' Boolean ';
};

JavaScript--To determine whether a data type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.