Question: As I know, it is possible to push more data into an array. Fe, I have an array: 

```
G = [12, 34, 5]. 

```

Right now, I can access the nth element like this: 

```
G[n]

```

I'd now like to push new data in it with a label, so I want the array to look like 

```
G = [12, 34, 5, label:567856, other: Infinity]

```

where I can get 567856 by calling 

```
G["label"] //(or Infinity by calling G["other"]). How can I achieve this? 

```

I've found 

```
G[i].push({
    label:567856, 
    other: Infinity
})

```

but this way it adds it as a whole new element, and I'm only able to call G[4]["other"], instead of G["other"]. How can I add the element as I've described?

Thank you!

Answer: 
To add onto Andriy's answer, you need to use Javascript Objects rather than arrays. An object can have indices with custom names. For example, given

```
var newObj = {"hello": "world", "value":1, "inf": Infinity}

```

you can do

```
newObj['hello'] // "world"
newObj['value'] // 1

```

The problem with

```
G[i].push({
    label:567856, 
    other: Infinity
})

```

is that you are pushing an object with 2 attributes, not pushing 2 objects, that's why you need to use `G[4]["other"]`

See running [JSFiddle example.](https://jsfiddle.net/fc0o5583/3/)
Arrays in JavaScript are a type of object. As such, they can contain properties:

```
G.label = 567856;
G.other = Infinity;

```

The advantage of arrays over other objects is that their indexed elements are *ordered*.

If you'd like the fourth and fifth elements in the array to be `567856` and `Infinity` *and* you want to be able to refer to those values with `G.label` and `G.other`, you can do so as follows:

```
var G = [12, 34, 5];

G.push(G.label = 567856);     //same as G.label = 567856;  G.push(G.label);
G.push(G.other = Infinity);

```

You can still iterate through the array using a loop:

```js
var G = [12, 34, 5];

G.push(G.label = 567856);    
G.push(G.other = Infinity);

G.forEach(function(val) {
  console.log(val);  // 12 ... 34 ... 5 ... 567856 ... Infinity
});

console.log(G.label);  //567856
console.log(G.other);  //Infinity
```

Note that this *does* create duplicates. If you change `G.label` or `G.other` afterwards, those changes will *not* be reflected in the fourth and fifth elements of the array.

However, you can overcome that by creating setters on `G.label` and `G.other` using [**Object.defineProperty()**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty):

```js
var G = [12, 34, 5];

G.push(G.label = 567856);
G.push(G.other = Infinity);

G.forEach(function(val) {
  console.log(val); // 12 ... 34 ... 5 ... 567856 ... Infinity
});

console.log(G.label); //567856
console.log(G.other); //Infinity

Object.defineProperty(G, 'label', {
  set: function(x) {
    this[3] = x;
  }
});

Object.defineProperty(G, 'other', {
  set: function(x) {
    this[4] = x;
  }
})

G.label = 99999;
G.other = 11111;

G.forEach(function(val) {
  console.log(val); // 12 ... 34 ... 5 ... 99999 ... 11111
});
```