0

Example -

var users = {

};

var conn = "ajey";

var ajey = {
  name: 'ajey',
  age: 25
}

users.conn = ajey;

This returns

[object Object] {
  conn: [object Object] {
    age: 25,
    name: "ajey"
  }
}

As you notice the object key is "conn" but how do I make it substitute the value of conn which is "ajey" ??

JS bin here

NOTE - I am not trying to access the object key. I am trying to set the object key with the value of a variable

Ajey
  • 7,924
  • 12
  • 62
  • 86
  • Look for "bracket notation" – elclanrs Aug 27 '14 at 07:26
  • @elclanrs: I am not trying to access the object key. I am trying to set the object key with the value of an existing variable – Ajey Aug 27 '14 at 07:28
  • @elclanrs How is it a duplicate question? – Ajey Aug 27 '14 at 07:32
  • 1
    It's about bracket notation, extrapolate... More dups, http://stackoverflow.com/questions/17189642/difference-between-using-bracket-and-dot-notation, http://stackoverflow.com/questions/4234777/javascript-different-behavior-when-using-dot-notation-vs-bracket-notation – elclanrs Aug 27 '14 at 07:34

0 Answers0