首页 > 编程语言 > 详细

区别array和数组的方法

时间:2020-07-02 12:46:18      阅读:63      评论:0      收藏:0      [点我收藏+]
 列举区别object,array的几种简单方法,特此记录下
    var arr = []
    var obj = {}
    // 1. 通过Array的isArray方法判读
    console.log(Array.isArray(arr)) //true
    console.log(Array.isArray(obj)) // false
 
    // 2.通过instancesOf 运算符
    console.log(arr instanceof Array) // true
    console.log(obj instanceof Array) // false
 
    // 3.通过数组prototype的isPrototypeOf方法
    console.log(Array.prototype.isPrototypeOf(arr)) // true
    console.log(Array.prototype.isPrototypeOf(obj)) // false
 
    // 4.通过构造函数constructor
    console.log(arr.constructor == Array) // true
    console.log(obj.constructor == Array) // false

区别array和数组的方法

原文:https://www.cnblogs.com/cjechenjinge-0820/p/13223794.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!