Home  >  Article  >  Web Front-end  >  Determine the data type of javascript (sample code)_javascript skills

Determine the data type of javascript (sample code)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:09:431120browse

1 Determine whether it is an array type

Copy code The code is as follows:

< script type="text/javascript">
//var a=[0];
document.write(isArray(a),'
');
function isArray(obj){
return (typeof obj=='object')&&obj.constructor==Array;
}
//]]>
< /script>


2 Determine whether it is a string type
Copy code The code is as follows:



3 Determine whether it is a numeric type
Copy code The code is as follows:



5 Determine whether it is a function
Copy code The code is as follows:



6 Determine whether it is an object
Copy code The code is as follows:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn