This post is the first of a series of bite-sized(like the title states) posts aimed to first of all remind me what each method of the
Table of contents
What’s an array?
At its core, an array is simply an ordered collection of items, nothing more, nothing less. When I was first learning to program, I always thought of an array, as my shopping list.
Please note that I did not say “sorted” list of items, that is something we are going to learn more about in future posts. The “ordered” part comes from the fact that an array keeps track of its items through indexes numbered from
length - 1.
Basically, if you have an array like the one below, its length is 5 and the index of the last item is 4, as index numbering starts from
var arr = ["a", "b", "c", "d", "e"]; // arr => a // arr => b // arr => c // arr => d // arr => e
Back to the shopping list analogy, your array of things to buy, would look like below:
var shoppingList = [ "carrots", "onions", "apples" ]; // shoppingList => carrots // shoppingList => onions // shoppingList => apples
There’s one more thing you need to know before we end for the day and that is the
length property of an array. Every time you query for the
length property of an array, you will get the exact number of items it holds.
Going back to our shopping list, let’s see how many items do we need to buy:
console.log(shoppingList.length); // => 3
Next, we will learn how to perform classic iteration on arrays, and also familiarize ourselves with our first
Matt Mets — 7x7 tri-color LED array