keyType(data) {

      let type = Object.prototype.toString.call(data);

      if (type === "[object String]") {

        type = "String";

      } else if (type === "[object Number]") {

        type = "Number";

      } else if (type === "[object Null]") {

        type = "Null";

      } else if (type === "[object Boolean]") {

        type = "Boolean";

      } else if (type === "[object Array]") {

        type = "Array";

      } else if (type === "[object Object]") {

        type = "Object";

      } else {

        type = "未进行判断的类型:" + type;

      }

      return type;

    },

如:

let arr = [1,2,3]; 

let type = this.keyType();

console.log("判断的类型", type);

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐