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: 
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;
  }, {});

```
You could modify your code to verify if the array was already created:

```
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] = {};
        if(theUser.hasOwnProperty(‘msg’) === false) {
            theUser.msg = [];
        }
        theUser.msg.push(i.nextElementSibling.nextElementSibling.innerHTML);
    }    
}

```