7. Arrays are Objects
When using the typeof operator in a JavaScript array, it returns an “object”.
This is because arrays are special types of objects. The difference between
arrays and objects is that when accessing an “element” of an array, numbers are
used as compared to objects that use names to access its “members”.
For example,
var arrPerson = ["Jack", "Sawyer", 28];
console.log(arrPerson[0]);
var objPerson = {firstName: "Jack", lastName: "Sawyer", age:28};
console.log(objPerson["firstName"]);
In the example above, both of them will print “Jack”. However, accessing “Jack” in the array uses the index 0 while the name firstName is used in the object.
The statement console.log(objPerson["firstName"]); could also be replaced with console.log(objPerson.firstName); and would still give you the same output. There are subtle differences between these two forms in accessing object items or elements and would leave that to you to experiment with them.