is declaring an array and initializing some arbitrary indexes allocate all the array elements in the memory even the undefined ones?
Example:
var users = [];
function addUser(userID, name, address) {
if (typeof (users[userID]) === 'undefined')
users[userID] = new User(userID, name, address)
}
function User (userID, name, address) {
this.userID = userID;
this.name = name;
this.address = address;
}
$(function () {
addUser(63, 'John', 'VA');
addUser(5, 'Kate', 'NY');
addUser(895, 'Yaz', 'DC');
});
So in the above example, will the browser allocate 896 instances of User in the memory (only 3 are defined) or only 3?
Thanks,
var arr = []; a[1000] = 42; console.dir(a);, then you will see that there is only one element in the array.