var names = [
“John”,
“Peter”,
“Carl”
];
and the end result would be identical. Any spaces outside of quotations are ignored with arrays, just like with objects.
You might be wondering how we work with an array. With objects we use the object.property notation in order to gain access to a value, so how do we do that with arrays when they don’t have any key names? Well, the answer is simple: we use what we call an ‘index number’. Every time we add a value to an array, it gets assigned a number, which auto increments from 0. Therefore, the very first item in any array, will have the index number of 0. Let’s see an example of this: