I found that both the Array Object and Array.prototype have the length property. I am confused on using the Array.length property. How do you use it?

Answer:

Array is a constructor function.

All functions have a length property that returns the number of declared parameters in the function definition.

Array.length is how many arguments the function Array() takes and Array.prototype.length is an instance method that gives you the length of your array. When you check ['foo'].length you're actually checking Array.prototype.length with the this argument being your array ['foo']

var myArray = ['a','b','c']
console.log(myArray.length); //logs 3

  

Array.length vs Array.prototype.length的更多相关文章

  1. typeof操作符,返回数据类型Array.isArray()、Object.prototype.toString.call()

    源地址https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/typeof typeof操作符 // N ...

  2. ES6数组的扩展--Array.from()和Array.of()

    一. Array.from() : 将伪数组对象或可遍历对象转换为真数组 1.何为伪数组 如果一个对象的所有键名都是正整数或零,并且有length属性,那么这个对象就很像数组,语法上称为"类 ...

  3. js--数组的 Array.of() 和 Array.from() 方法的使用总结

    前言 JavaScript 中数组的本质是一个对象,它存在的 length 属性值随数组元素的长度变化,但是开发中经常会遇到拥有 length 属性和若干索引属性的对象,被称为类数组对象,类数组对象和 ...

  4. es6 --数组--Array.from() 、Array.isArray()、Array.of()、find()、findIndex()、fill()、entries() 、keys() ,values()

    将两类对象转为真正的数组 Array.from()方法用于将两类对象转为真正的数组:类似数组的对象(array-like object)和可遍历(iterable)的对象(包括ES6新增的数据结构Se ...

  5. Array.of()和Array()区别

    Array.of方法用于将一组值,转换为数组. Array.of(3, 11, 8) // [3,11,8] Array.of(3) // [3] Array.of(3).length // 1 这个 ...

  6. sklearn中报错ValueError: Expected 2D array, got 1D array instead:

    from sklearn.linear_model import LinearRegression lr = LinearRegression() print(tr_x.shape,tr_y.shap ...

  7. From Ruby array to JS array in Rails- 'quote'?

    From Ruby array to JS array in Rails- 'quote'? <%= raw @location_list.as_json %>

  8. FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length

    FireDAC 出现Variable length column[*] overflow. Value length - [80], column maximum length FireDAC的 TF ...

  9. [Python] Indexing An Array With Another Array with numpy

    NumPy Reference: Indexing Integer array indexing: Select array elements with another array def index ...

随机推荐

  1. iOS毛玻璃擦除效果

    思路:首先我的思路放两个imageView在Controller里把高清的图片放在下面,带有毛玻璃效果的图片放在上面. //在Controller的view上加一个手势代码如下(温馨提示,开启imae ...

  2. php 随笔

    <?php header("content-type:text/html;charset=utf8");class Car {   var  $name = '汽车';    ...

  3. Ubuntu安装Mysql过程及远程问题解决

    ubuntu下执行 sudo apt-get instlll mysql-server sudo apt-get install mysql-client 安装过程中会有文字界面设置密码 牢记密码 M ...

  4. js函数的一些技巧

    1 函数的引用可以直接通过函数名来调用 bind: function (fn, scope) { return function () { return fn.apply(scope, argumen ...

  5. JS预览图像将本地图片显示到浏览器上

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  6. Gentoo挂载ntfs的NTFS分区

    内核需要开启的选项 File systems ---> <*> FUSE (Filesystem in Userspace) support 使用NTFS-3G NTFS-3G是一个 ...

  7. 自定义alert和confirm

    var common = {}; common.showAlert = function (msg) { var html = "<div id='dialog_alert' clas ...

  8. Session和Cookie的使用总结

    Session和Cookie的使用总结: Session和cookie都是asp.Net中的内置对象,至于他们有什么区别,在这里就不在多说,现在来说说一些比较实用点的东西: 我们知道网站都有一个后台管 ...

  9. PHP7编译错误:php编译undefined reference to `libiconv 错误

    ext/gd/libgd/.libs/gdkanji.o: In function `do_convert’: /root/php-5.2.12/ext/gd/libgd/gdkanji.c:350: ...

  10. Oracle结构知识学习+部分函数实例

    一 Oracle的结构1 实例(instance) 是内存和后台进程的集合, 数据库是数据的物理储存;实例和数据库的关系是一对多的关系;2 多个实例同时驱动一个'数据库'的架构 叫集群(RAC)3 O ...