Question: ```
var user = {};
var usernameList = document.querySelectorAll('.msg.g_bot.bot.private.i ~ .msg .usr');
for (i of usernameList) {
    if (i.childNodes[0].nodeName === 'SPAN') {
        var theUser = (user[i.childNodes[0].innerHTML] !== undefined) ? user[i.childNodes[0].innerHTML] : user[i.childNodes[0].innerHTML] = {};
        var msg = theUser.msg = [];
        msg.push(i.nextElementSibling.nextElementSibling.innerHTML);
    }    
}

```

The object `user.whatever.msg` is an array but contains only 1 value. So it's always the last one. In this case `push` doesn't work, so I can't put all values into that array.

What's wrong with my code?

Answer: 
`theUser.msg = [];` does create a new array on every iteration. Just like you create a new `theUser` object only when it doesn't exist already, you should only create the `msg` array only once.

```
var users = {};
var usernameList = document.querySelectorAll('.msg.g_bot.bot.private.i ~ .msg .usr');
for (var i of usernameList) {
    if (i.firstChild.nodeName === 'SPAN') {
        var name = i.firstChild.innerHTML; // should be .textContent probably
        var theUser = name in user
          ? user[name]
          : user[name] = { msg: [] };
//                        ^^^^^^^^^
        theUser.msg.push(i.nextElementSibling.nextElementSibling.innerHTML);
    }
}

```
A clearer way of doing it would be to use `.reduce`:

```
const user = [...document.querySelectorAll('.msg.g_bot.bot.private.i ~ .msg .usr')]
  .reduce((userObj, i) => {
    if (i.childNodes[0].nodeName !== 'SPAN') return userObj;
    const childHtml = i.childNodes[0].innerHTML;
    const theUser = userObj[childHtml] || { msg: [] };
    theUser.msg.push(i.nextElementSibling.nextElementSibling.innerHTML)
    return userObj;
  }, {});

```