Arrays in JavaScript
In JavaScript, arrays can store multiple elements. Each element in the array is separated by a comma (,)
. Elements of different data types can also be stored in a single JavaScript array, but this is a little tricky. Nonetheless, it is possible, and this allows JavaScript arrays to store a string, number, or even another array within a single array!
Now let's consider an example. Suppose we have a list of names to store in the list. The list will be initialized by giving it a name (like variables) and specifying all elements in the list separated by a comma.
JAVASCRIPT
1var name = ["Alice", "Mona", "Bob", "Barbara"]