js判断数据类型

时间:2023-01-10 10:14:12
 1 //是否是json类型
2 function isJson(data){
3 return (typeof data === 'object' && data+'' === '[object Object]');
4 }
5 //是否是数组
6 function isArray(data){
7 return data instanceof Array;
8 }
9 //是否是简单类型
10 function isSimple(data){
11 if(typeof data === 'number' || typeof data === 'string' || typeof data === 'boolean'){
12 return true;
13 }else{
14 return false;
15 }
16 }
17 //是否是引用类型
18 function isRef(data){
19 return !isSimple(data)
20 }

js判断数据类型