什么是这些阵列之间的区别? [英] What is the difference between these arrays?
问题描述
无功富= {}
VAR栏=新的Array();
变种另一= [];
此外,是否有可能加入到富
像这样:
富['OBJ'] =新的日期();
无功富= {};
块引用>
富
是一个对象字面。VAR栏=新的Array();
块引用>
栏
是通过阵列
构造函数初始化数组。VAR另一= [];
块引用>
另一个
是文字的数组。通过文字创建新阵列是不是通过阵列
构造这样做更有效的:的 http://jsperf.com/new-array 而且这也更容易输入。)我会建议使用数组文本尽可能
此外,是否有可能在富添加像这样:
富['OBJ'] =新的日期();
块引用>是的。这将添加属性
OBJ
到富
含)新日期的值(
。这是相当于以foo.obj =新的日期();
。var foo = {} var bar = new Array(); var another = [];
Also, is it possible to add to
foo
like so:foo['obj'] = new Date();
解决方案var foo = {};
foo
is an object literal.var bar = new Array();
bar
is an array initialized via theArray
constructor.var another = [];
another
is an array literal. Creating new arrays through literals is more efficient than doing so through theArray
constructor: http://jsperf.com/new-array And it’s also much easier to type ;) I’d recommend using array literals wherever possible.Also, is it possible to add in foo like so:
foo['obj'] = new Date();
Yes. That will add a property
obj
tofoo
with the value ofnew Date()
. It’s equivalent tofoo.obj = new Date();
.这篇关于什么是这些阵列之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!