📜  JavaScript中数组和对象数组的区别

📅  最后修改于: 2022-05-13 01:56:11.934000             🧑  作者: Mango

JavaScript中数组和对象数组的区别

在本文中,我们将看到 JavaScript 中数组和对象数组之间的区别。

1. 数组:数组是数据的集合和存储在一系列内存位置中的数据结构。可以通过调用索引号来访问数组的元素,例如 0、1、2、3、……等。数组可以存储Integer、Float、String 和 Boolean 等所有原始数据类型在一个数组中。

例子:

Javascript


Javascript


输出:

2.对象数组: It 将多个值存储在单个变量中。该对象可以包含现实世界中的任何事物,例如人名、汽车、游戏字符。如果您知道数据在哪里处理,则在某些情况下对象非常容易使用。对象的字符集称为Properties 。可以使用DOT 表示法[] 表示法调用对象的属性。

例子:

Javascript


输出:

数组和对象数组的区别:

S. No.

Array

Array of objects

1.Arrays are best to use when the elements are numbers.objects are best to use when the elements strings (text).
2.The data inside an array is known as Elements.The data inside objects are known as Properties that consist of a key and a value.
3.The elements can be manipulated using [].  The properties can be manipulated using both .DOT notation and [].
4.The elements can be popped out of an array using the pop() function.The keys or properties can be deleted by using the delete keyword.
5.Iterating through an array is possible using For loop, For..in, For..of, and ForEach().Iterating through an array of objects is possible using For..in, For..of, and ForEach().