Skip to main content

JavaScript JSON array

A JSON array literal is a JavaScript array that is written in JSON syntax. It consists of a list of values enclosed in square brackets, with each value separated by a comma.

Here's an example of a JSON array literal:

[ "apple", "banana", "cherry" ]

In this example

  • We have a JSON array with three values: "apple", "banana", and "cherry".

JSON array literals are commonly used to represent collections of data in web applications, especially when communicating with web APIs that use JSON as their data format. They are also commonly used for data storage and exchange in databases and other data systems.

Here's an example of a JSON array literal that includes objects as its values:

[
{ "name": "John", "age": 30 },
{ "name": "Jane", "age": 25 },
{ "name": "Bob", "age": 40 }
]

In this example:

  • We have a JSON array with three objects as its values.
  • Each object has two key-value pairs: "name" and "age".
  • This type of JSON array is often used to represent collections of related objects, such as a list of users or products.