Question: I have this Javascript variable :

```
var Item_properties = {
   id : null,
   keys : [],
   hydrate: function() {
       //get data
       this.id = $('input[id=id]').val();

       $("#item_key div input").each(function(index) {
          this.keys.push($(this).val());
       });
}

```

It is impossible to push any data in keys array, I'm getting the message : 
Cannot call method 'push' of undefined

Any idea ?

Answer: 
jQuery sets `this` to the DOM element in the callback to `.each`. You can save `this` into a variable and then use it.

```
var self = this;
$("#item_key div input").each(function(index) {
  self.keys.push($(this).val()));
}

```
While [two](https://stackoverflow.com/a/16317950/887149) other [answers](https://stackoverflow.com/a/16317947/887149) are ok, here is another way to do it.

You can use 

```
Item_properties.keys.push($(this).val());

```

Instead of 

```
this.keys.push($(this).val());

```