javascript类型判断

判断String类型

1
2
3
function isString(value) {
return typeof value === 'string';
};

判断Number类型

1
2
3
function(value) {
return typeof value === 'number';
};

判断function

1
2
3
function isFunction(value) {
return typeof value === 'function';
};

判断正则表达式类型

1
2
3
function isRegExp(value) {
return toString.call(value) === '[object RegExp]';
}

判断是否是对象

1
2
3
function isObject(value){
return value !== null && typeof value === 'object';
}

判断是否是Object的对象

1
2
3
function isBlankObject(value) {
return value !== null && typeof value === 'object' && ! getPrototypeOf(value);
};

判断是否是数组

1
2
3
4
5
6
function isArray(value){
if (Object.prototype.toString.apply(arr) === '[object Array]')
return true;
else
return false;
}
文章目录
  1. 1. 判断String类型
  2. 2. 判断Number类型
  3. 3. 判断function
  4. 4. 判断正则表达式类型
  5. 5. 判断是否是对象
  6. 6. 判断是否是Object的对象
  7. 7. 判断是否是数组
,