What I have learned is an array is a type of object. Objects are a collection of properties with key/value pairs. I always thought arrays are a collection of items that are numerically indexed starting at 0. Just recently, I was able to add a non-numeric key to an array.
let arr = ['cribriform plate','mastoid','hyoid'];
arr.eyes = 'brown';
arr.skin = 'white';
That resulted in
['cribriform plate','mastoid','hyoid',eyes : 'brown', skin : 'white'];
The for...in loop of arr yielded:
for(let i in arr){
console.log(i);
//0,1,2,3,eyes,skin
}
The for...of loop yielded:
for(let i of arr){
console.log(i);
//0,1,2,3
}
I was able to iterate over all the keys of an array using the for...in loop. However, when I used the for...of loop, I was only able to iterate over the numerically indexed keys. Why is that?
And, what is the most accurate definition of an array?