Get the name of an object's type

前端 未结 20 2273
忘掉有多难
忘掉有多难 2020-11-21 22:37

Is there a JavaScript equivalent of Java\'s class.getName()?

20条回答
  •  长发绾君心
    2020-11-21 22:53

    Say you have var obj;

    If you just want the name of obj's type, like "Object", "Array", or "String", you can use this:

    Object.prototype.toString.call(obj).split(' ')[1].replace(']', '');
    

提交回复
热议问题