获取变量类型

function getType(v){
    let type = Object.prototype.toString.call(v);
    let arr = type.split(" ");
    let str = arr[1].slice(0,-1);
    return str;
}


let time = new Date();
console.log(getType(time));   //Date

(()=>{
    let type = getType(arguments)
    console.log(type);     //Arguments
})();

let arr = [1,2,3];
console.log(getType(arr));   //Array

 

你可能感兴趣的:(node,web前端)