Arrays are ordered collections of elements, which can be of any data type, including other arrays and objects. They are created using square brackets
Here's how to create an array:
Accessing Array Elements
To access an array element, use its index (zero-based) within square brackets:
Modifying Array Elements
To modify an array element, assign a new value to the desired index:
splice(), and more.
Objects are collections of key-value pairs, where keys are strings, and values can be of any data type, including other objects and arrays. They are created using curly braces
Here's how to create an object:
Accessing Object Properties
To access an object property, use either dot notation or square brackets with the property name:
Modifying Object Properties
To modify an object property, assign a new value to the desired key:
Object.entries(), and more.
Array constructor or the array literal syntax. Here's an example:
To access elements in an array, use the index of the element you want to access, like so:
Object constructor or the object literal syntax. Here's an example:
To access properties in an object, you can use either the dot notation or the bracket notation, like so:
How do I add, remove, or modify elements in arrays and objects?
To add, remove, or modify elements in arrays, you can use various built-in methods like
splice, and more. For objects, you can simply assign a new value to an existing property, add a new property, or delete a property using the
delete keyword. Here are some examples: