zoukankan      html  css  js  c++  java
  • 判断数据类型

    一,Array.isArray() 用于确定传递的值是否是一个 Array

    Array.isArray([1, 2, 3]);  
    // true
    Array.isArray({foo: 123}); 
    // false
    Array.isArray("foobar");   
    // false
    Array.isArray(undefined);  
    // false

    文档:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

    二,typeof

    console.log(typeof 42);
    // expected output: "number"
    
    console.log(typeof 'blubber');
    // expected output: "string"
    
    console.log(typeof true);
    // expected output: "boolean"
    
    console.log(typeof declaredButUndefinedVariable);
    // expected output: "undefined";

    文档:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/typeof

    三,Object.prototype.toString.call

    console.log(Object.prototype.toString.call("jerry"));//[object String]
    console.log(Object.prototype.toString.call(12));//[object Number]
    console.log(Object.prototype.toString.call(true));//[object Boolean]
    console.log(Object.prototype.toString.call(undefined));//[object Undefined]
    console.log(Object.prototype.toString.call(null));//[object Null]
    console.log(Object.prototype.toString.call({name: "jerry"}));//[object Object]
    console.log(Object.prototype.toString.call(function(){}));//[object Function]
    console.log(Object.prototype.toString.call([]));//[object Array]
    console.log(Object.prototype.toString.call(new Date));//[object Date]
    console.log(Object.prototype.toString.call(/d/));//[object RegExp]
    function Person(){};
    console.log(Object.prototype.toString.call(new Person));//[object Object]

    文档:https://www.cnblogs.com/youhong/p/6209054.html

  • 相关阅读:
    openstack命令行
    Hub, bridge, switch, router, gateway的区别
    openstack奠基篇:devstack (liberty)于centos 7安装
    git常用命令备忘
    如何利用gatling创建一个性能测试例
    如何通过源码生成Gatling可执行工具
    博客园的第一篇博文
    Spring Oauth2 with JWT Sample
    你首先是一个人,然后你才是程序员。
    Maven——快速入门手册(学习记录) ****
  • 原文地址:https://www.cnblogs.com/wang715100018066/p/8745633.html
Copyright © 2011-2022 走看看