The Array Literal Syntax [ ]
Definition
The [ ] literal is the syntax to initialize an array.
While it is technically a literal syntax rather than an operator, it is how arrays are structured.
Note
In JavaScript, the [ ] symbol serves different purposes depending on how it is used:
- Property Accessor
let name = car["name"] - Array Literal Syntax
const fruits = ["apple", "banana"] - Array Destructuring
const [first, second] = fruits; - Computed Property Names
const obj = {[dynamicKey]: "value"}
Browser Support
[] is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |