0

I am having a data like this in jquery how do i get the groupname2 values from the grouplist that user1,user2 etc:

{"groupslist":{"groupname":["user1","user2","user3"],"groupname2":["user1","user2","user3"],"groupname3":["user1","user2","user3"]}}

i have declared grouplist={} and push the groupname values dynamically what i get in console when i print grouplist is `

Object {user00: Array[3], super user: Array[1], supreme user: Array[0]}
super user: Array[1]
0: "sample_vh.com"
length: 1
__proto__: Array[0]
supreme user: Array[0]
user00: Array[3]
0: "veera_tls.com"
1: "v_v.com"
2: "sample_vh.com"
length: 3
__proto__: Array[0]
__proto__: Object`
user3502260
  • 220
  • 1
  • 2
  • 10
Chawla
  • 48
  • 1
  • 5
  • 1
    `grouplist.groupslist.groupname2` will return the array, `grouplist.groupslist.groupname2[0]` will return string `user1` – A. Wolff Apr 06 '14 at 14:54
  • possible duplicate of [Access / process (nested) objects, arrays or JSON](http://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – Felix Kling Apr 06 '14 at 16:20
  • console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+grouplist); am getting [object object] what it mean?? – Chawla Apr 07 '14 at 03:07

2 Answers2

3
var o = {
  "groupslist":{
    "groupname":["user1","user2","user3"],
    "groupname2":["user1","user2","user3"],
    "groupname3":["user1","user2","user3"]
  }
};

console.log(o.groupslist.groupname2);
phylax
  • 2,034
  • 14
  • 13
  • console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+grouplist); am getting [object object] what it mean?? – Chawla Apr 07 '14 at 03:08
  • @Chawla it means by concatting the object `grouplist` with the string `zzzzz` JavaScript has to convert `grouplist` to a string. Since `grouplist` has no `toString()` method JavaScript dont know better as to use `[object object]`. Compare: `String({})`. – phylax Apr 07 '14 at 08:06
0

Your data can access like this :

var mylist = {"groupslist":{"groupname":["user1","user2","user3"],"groupname2":["user1","user2","user3"],"groupname3":["user1","user2","user3"]}};
console.log(mylist.groupslist.groupname2)

Example : http://jsfiddle.net/b3jVX/

Le Trong
  • 144
  • 1
  • 7
  • console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+grouplist); am getting [object object] what it mean?? – Chawla Apr 07 '14 at 03:11