JS determines whether the data type is a string for the array, and so on

Source: Internet
Author: User
Tags cdata constructor numeric

 js to determine whether a data type is an array type, judge whether it is a string type, determine whether it is a numeric type, and so on, this article has several good examples where you can learn

1 Determines whether the array type   2 determines whether the string type   3 determines whether the value type   4 determines whether the date type   5 Determines whether it is a function of   6 to determine whether the object is the     1 to determine whether the array Type     code is as follows: <script type= "Text/javascript" > //<! [cdata[  var a=[0];  document.write (IsArray (a), ' <br/> ');  function IsArray (obj) {  return ( typeof obj== ' object ') &&obj.constructor==Array; } //]]>  </script>    2 Determine if the string type   code is as follows: <script type= "Text/javascript" > //<! [cdata[  document.write (isstring (' Test '), ' <br/> ');  document.write (isstring, ' <br/> ');   function isstring (str) {  return (typeof str== ' string ') &&str.constructor==String; } // ]]>  </script>    3 to determine whether the numeric type   code is as follows: <script type= "Text/javascript" > //<! [cdata[  document.write (isnumber (' Test '), ' <br/> ');  document.write (isnumber, ' <br/> ');   function Isnumber (obj) {  return (typeof obj== ' number ') &&obj.constructor==Number; } //]]>  </script>    4 Determine if the date type   code is as follows: <script type= "Text/javascript" > //<! [cdata[  document.write (isDate (new Date), ' <br/> ');  document.write (IsDate (a), ' <br/> ');   function isDate (obj) {  return (typeof obj== ' object ') &&obj.constructor==Date; } //] >  </script>    5 to determine whether the function     code is as follows: <script type= "Text/javascript" > //< ! [cdata[  document.write (isfunction (function test () {}), ' <br/> ');  document.write (Isfunction (10), ' <br/> ');  function isfunction (obj) {  return (typeof obj== ' function ') &&obj.constructor== function; } //]]>  </script>    6 to determine whether the object   code is as follows: <script type= "text/ JavaScript "> //<! [cdata[  document.write (IsObject (new Object), ' <br/> ');  document.write (IsObject (10),' <br/> ');  function IsObject (obj) {  return (typeof obj== ' object ') &&obj.constructor==Object;  } //]]>  </script>   

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.