美文网首页
JS判断数据类型

JS判断数据类型

作者: LHQ丶 | 来源:发表于2021-07-10 16:11 被阅读0次
var type = function (o){
  var s = Object.prototype.toString.call(o);
  return s.match(/\[object (.*?)\]/)[1].toLowerCase();
};
 
type({}); // "object"
type([]); // "array"
type(5); // "number"
type(null); // "null"
type(); // "undefined"
type(/abcd/); // "regex"
type(new Date()); // "date"

相关文章

网友评论

      本文标题:JS判断数据类型

      本文链接:https://www.haomeiwen.com/subject/unsfpltx.html