JavaScript 对象字面量和数组字面量

标签 javascript

JavaScript 中的对象字面量和数组字面量有什么区别?我知道它与长度方法有关,但我不完全理解。

最佳答案

Mozilla.org通过示例很好地解释了不同的文字。

Array Literals

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.

Object Literals

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 对象字面量和数组字面量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/500583/

相关文章:

javascript - 从 busboy 管道流到请求帖子

c# - New Breeze 1.4.9 - 重复的实体 - 可能的错误?

javascript - 可以切换的图像网格,需要帮助保存选定的图像

javascript - NodeJS 套接字发出返回未定义

javascript - 关于 nodejs server.listen()

javascript - 将图像放入容器中,即使 src 已更改

javascript - 简单的点击事件可以在 Ubuntu 的触摸屏设备上使用

javascript - WCF 服务 - 使用 AJAX 将存储过程名称作为数据传递

javascript - 首次运行后链接不会切换

javascript - TinyMCE,允许数据属性