Empty Arrays

By: Dusty Arlia
Published on September 11, 2012
Last Updated on Wednesday, July 08, 2015 at 8:40 PM
Total Updates: 6

There will be times when you need an array, but you will not know the values for the elements upfront. In these situations you will need to make use of empty arrays. You can create an empty array like this:

var shoppingCart = [];

In this example, when people add something to their shopping cart on your website, the array gets assigned values. Because you don't know what your visitors are going to select prior to visiting your website, you must make use of an empty array.