Sparse arrays in JavaScript
If there are gaps in the sequence of keys in the array, then you can get a sparse array. Let's see what it looks like. Let's have some array:
javascriptlet arr = ['a', 'b', 'c'];
Let's add one more element to this array so that the sequence of keys have gaps:
javascriptarr[4] = '!';
As a result, a "hole", which has the value undefined, appears in the array:
javascriptconsole.log(arr); // shows ['a', 'b', 'c', undefined, '!']
The length of the array will consider
all holes. That is, in our case, it
will be 5, and not 4:
javascriptconsole.log(arr.length); // shows 5
Задание 1
Find out the length of the next array:
javascriptlet arr = [];
arr[3] = 'a';
arr[8] = 'b';