什么是这些阵列之间的区别? [英] What is the difference between these arrays?

查看:165
本文介绍了什么是这些阵列之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 无功富= {}
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 the Array constructor.

var another = [];

another is an array literal. Creating new arrays through literals is more efficient than doing so through the Array 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 to foo with the value of new Date(). It’s equivalent to foo.obj = new Date();.

这篇关于什么是这些阵列之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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