压缩数组和文字数组有什么区别? [英] What is the difference between condensed arrays and literal arrays?

查看:49
本文介绍了压缩数组和文字数组有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说:压缩数组和文字数组有什么区别?

As the title says: What is the difference between condensed arrays and literal arrays?

new Array("John", "Bob", "Sue"); // condensed array

["John", "Bob", "Sue"]; // literal array

有些事情我可以用一个做而另一个我不能做吗?还是它在内存中的保存方式?

Are there things I can do with one that I can't do with the other? Or is it the way it is kept in the memory?

推荐答案

没有,生成的对象没有区别,都是一样的.

No, there is no difference in the produced object, they are the same.

第一个是尝试满足习惯于经典"环境的程序员的需求,在这种环境中您必须实例化新"数组对象.

The first is an attempt to satisfy programmers that are use to a "classical" environment where you have to instantiate a "new" Array object.

需要注意的是,javascript中的数组不是内存的顺序分配,而是具有可枚举属性名称和一些额外(有用)方法的对象.

It should be noted that Arrays in javascript are not a sequential allocation of memory, but objects with enumerable property names and a few extra (useful) methods.

因为这在大多数(如果不是全部)情况下创建一个固定长度的数组是相当无用和不必要的.

Because of this creating an array of a set length is fairly useless and unnecessary in most (if not all) cases.

var array = new Array(10);

在功能上相同的是手动设置数组的长度

is functionally the same is manually setting the length of your array

var array = [];
array.length = 10;

这篇关于压缩数组和文字数组有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆