1 Determine whether it is an array type
2 Determine whether it is a string type
3 Determine whether it is a numerical type
4 Determine whether it is the date type
5 Determine whether it is a function
6 Determine whether it is an object
1 Determine whether it is an array type
Copy code code as follows:
<script type = "text/javascript">
// <! [Cdata [cdata [
var a = [0];
document.write (Isarray (a), '<br/>');
function isarray (obj) {
Return (Typeof Obj == 'Object') && Obj.ConStructor == Array;
}
//]]>
</script>
2 Determine whether it is a string type
Copy code code as follows:
<script type = "text/javascript">
// <! [Cdata [cdata [
document.write (isstring ('test'), '<br/>');
document.write (isstring (10), '<br/>');
function isstring (STR) {
Return (Typeof Str == 'String') && Str.ConStructor == String;
}
//]]>
</script>
3 Determine whether it is a numerical type
Copy code code as follows:
<script type = "text/javascript">
// <! [Cdata [cdata [
document.write (isnumber ('test'), '<br/>');
document.write (isnumber (10), '<br/>');
function isnumber (obj) {
Return (Typeof Obj == 'Number') && Obj.ConStructor == Number;
}
//]]>
</script>
4 Determine whether it is the date type
Copy code code as follows:
<script type = "text/javascript">
// <! [Cdata [cdata [
document.write (isdate (new date ()), '<br/>');
document.write (isdate (10), '<br/>');
Function isdate (obj) {
Return (Typeof Obj == 'Object') && Obj.ConStructor == Date;
}
//]]>
</script>
5 Determine whether it is a function
Copy code code as follows:
<script type = "text/javascript">
// <! [Cdata [cdata [
document.write (isfunction (function test () {}), '<br/>');
document.write (isfunction (10), '<br/>');
Function Isfunction (OBJ) {
Return (Typeof Obj == 'Function') && Obj.ConStructor == Function;
}
//]]>
</script>
6 Determine whether it is an object
Copy code code as follows:
<script type = "text/javascript">
// <! [Cdata [cdata [
document.write (isObject (New Object ()), '<br/>');
document.write (isobject (10), '<br/>');
function isObject (OBJ) {
Return (Typeof Obj == 'Object') && Obj.ConStructor == Object;
}
//]]>
</script>