I have a question that may seem silly: How can we accurately determine the length of an array in JavaScript? Specifically, I want to find the total number of positions occupied in the array.
Most of you may already be familiar with this simple scenario.
var a = [1,2,3];
a.length; //This will give us 3
Now, if I do
a[100] = 100;
a.length; // The result is 101;
I am looking to retrieve the precise size of the array, which in the above case should be 4.