Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
class test 
{
    constructor()
    {
        console.log("new object created");
        this.test = { arr : {} };
    }
    static init()
    {
      return new test();
    }
    add()
    {
        let user_id = Math.floor(Math.random() * 10000);
        if(this.test.arr["u_" + user_id] === undefined)
        {
            this.test.arr["u_" + user_id] = [];
        }
        this.test.arr["u_" + user_id].push({"somedata": "here"});
        console.log("new item added - " + this.length() + " items ttl");
    }
    length()
    {
      return Object.keys(this.test.arr).length;
    }
}
var x = test.init();
x.add();
x.add();
console.log(x.length());
console.log(JSON.stringify(x));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
MrFinipro
0viewers