function on a variable containing an array, it will return an 'object'.
var arr = [1, 2, 3];
Copy PRACTICE IT
You will learn more about objects in subsequent pages but understand that objects are more like arrays containing properties and methods.
The reason for all the above explanation is to bring to your knowledge that arrays can be created the explicit or literal way(easiest and recommended) and the implicit or object way(not really recommended but does same thing).
The Explicit Method
This method involves having all the values of any array in a bracket ([ ]
) while separating each value from the other with a comma (,
The Implicit Method
var arr = [value1, value2, ...];
var myArray = [1, 2, 3, 4];
keyword. You will learn about this in subsequent pages.
So, to create arrays this way, you simply have your various values contained and separated with a comma(,) inside the new Array()
var arr = new Array(value1, value2, ...);
var myArray = new Array(1, 2, 3, 4);
The explicit and implicit methods of creating arrays does same thing which is to create an array or a new array.
Remember also that any array can contain values of just any data type. Be it numbers, strings, booleans, arrays, objects and functions.
- Arrays can be created the explicit or implicit way.
- The explicit way involves having your numerous array values inside a bracket ([ ]).
- The implicit method involves the direct creation of an array from the array object, Array. We use the new keyword alongside the array object and have our individual values inside of it e.g new Array(1, 2, 4).
- Individual values of an array are separated with a comma(,) and the values can be of just any data type including other arrays.
- Both the explicit and implicit methods of creating an array does same thing which is to create an array.