js 获取数据类型

2021-03-30 07:25

阅读:403

标签:efi   取数据   define   var   javascrip   map   ceo   rip   数据类型   

const getObjType = function (obj){
    var toString = Object.prototype.toString;
    var map = {
        ‘[object Boolean]‘: ‘boolean‘,
        ‘[object Number]‘: ‘number‘,
        ‘[object String]‘: ‘string‘,
        ‘[object Function]‘: ‘function‘,
        ‘[object Array]‘: ‘array‘,
        ‘[object Date]‘: ‘date‘,
        ‘[object RegExp]‘: ‘regExp‘,
        ‘[object Undefined]‘: ‘undefined‘,
        ‘[object Null]‘: ‘null‘,
        ‘[object Object]‘: ‘object‘
    };
    if (obj instanceof Element) {
        return ‘element‘;
    }
    return map[toString.call(obj)];
};

  

js 获取数据类型

标签:efi   取数据   define   var   javascrip   map   ceo   rip   数据类型   

原文地址:https://www.cnblogs.com/wangyunhui/p/12598909.html


评论


亲,登录后才可以留言!