Objects and Arrays

In JavaScript, an object is a collection of key-value pairs, where the keys are strings and the values can be of any data type (including other objects). Objects are defined using curly braces {} and the key-value pairs are separated by commas.

const obj = { key1: value1, key2: value2, ... };

An array is an ordered list of values, where each value can be of any data type (including other arrays and objects). Arrays are defined using square brackets [].

The syntax for creating an array is:

const arr = [value1, value2, ...];


Objects and arrays are fundamental data structures in JavaScript and are used to represent complex data and relationships between data. Understanding objects and arrays is essential for working with data in JavaScript.