JavaScript multidimensional array length always returning 0, how can I solve this problem?
class test {
static init() {
test.arr = [];
}
static add() {
let user_id = Math.floor(Math.random() * 10000);
if (test.arr["u_" + user_id] === undefined) {
test.arr["u_" + user_id] = [];
}
test.arr["u_" + user_id].push({
"somedata": "here"
});
}
static length() {
return test.arr.length;
}
}
test.init();
test.add();
test.add();
console.log(test.arr.length); //Always returning 0