1

How can I name my site object's key with a variable value ? because when I write "site", the output is equal to the word "site" and not the variable value.

  dataArray = {
    sites: {
      site: {
        username: username,
        followers: followers,
        details: details,
        diff: 0
      }
    },
    graph: {
      data: [0, 0, 0, 0, 0, 0]
    },
    sort: {
      order: [0, 1, 2, 3, 4, 5]
    }
  };

In order to retrieve something like this :

{
  "sites":{
    "dribbble":{
      "username":"JeremDsgn",
      "followers":17,
      "details":{
        "following":14,
        "likes":8,
        "comments":4,
        "views":252
      },
      "diff":0
    },
    "twitter":{
      "username":"JeremDsgn",
      "followers":17,
      "details":{
        "following":14,
        "likes":8,
        "comments":4,
        "views":252
      },
      "diff":0
    }
  },
  "graph":{
    "data": [0, 0, 0, 0, 0, 0]
  },
  "sort":{
    "order": [0, 1, 2, 3, 4, 5]
  }
}
jeremybarbet
  • 890
  • 1
  • 15
  • 28
  • http://stackoverflow.com/questions/2241875/how-to-create-object-property-from-variable-value-in-javascript – dfsq Jun 14 '14 at 14:45

0 Answers0