JavaScript Object Literals&数组文字 [英] JavaScript Object Literals & Array Literals

查看:91
本文介绍了JavaScript Object Literals&数组文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript中的Object Literals和Array Literals有什么区别?我知道它与长度方法有关但我不完全理解它。

What is the difference between Object Literals and Array Literals in JavaScript? I know it has something to do with the length method but i don't fully understand it.

推荐答案

Mozilla.org 通过示例对不同的文字进行了非常好的解释。

Mozilla.org has very good explanation of the different literals with examples.


数组文字

数组文字是一个零或
多个表达式的列表,每个表达式都是
表示一个数组元素,包含$方括号中的b $ b([])。当
使用数组
literal创建数组时,它使用
指定值作为其元素进行初始化,
将其长度设置为
指定的参数。

An array literal is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ([]). When you create an array using an array literal, it is initialized with the specified values as its elements, and its length is set to the number of arguments specified.

对象文字

对象文字是零列表或
更多对属性名称和
对象的关联值,
用大括号({})括起来。你
不应该在
语句的开头使用对象文字。这个
将导致错误或不符合您期望的
,因为{将
解释为
块的开头。

An object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces ({}). You should not use an object literal at the beginning of a statement. This will lead to an error or not behave as you expect, because the { will be interpreted as the beginning of a block.

这篇关于JavaScript Object Literals&数组文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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