In JavaScript, an array is an ordered list of values. Each value is called an element specified by an index:
1- An array can hold values of mixed types.
For example, you can have an array that stores elements with the types number, string, boolean, and null.
2- The size of an array is dynamic and auto-growing.
In other words, you don’t need to specify the array size up front.
Ways of declaring an array
It does NOT have to be a number, like here we have an expression
An expression produce a value
We can NOT put a statement inside the []
. it expect a value (expression).
console.log(friends[friends.length - 1]);
Change or mutate the array
Even I declared the array with const
, I still can make changes, this is because only primitive values, are immutable.
Arrays, they are NOT a primitive values, so we can mutate them.
Array - methods
We are gonna use push(), but there's more actually
The push()
method in JavaScript adds new items to the end of an array.
The push()
method returns the new value of the length property of the array object on which you call the method.
Top comments (0)