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`
3
  • 1
    grouplist.groupslist.groupname2 will return the array, grouplist.groupslist.groupname2[0] will return string user1 Commented Apr 6, 2014 at 14:54
  • possible duplicate of Access / process (nested) objects, arrays or JSON Commented Apr 6, 2014 at 16:20
  • console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+grouplist); am getting [object object] what it mean?? Commented Apr 7, 2014 at 3:07

2 Answers 2

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

console.log(o.groupslist.groupname2);
Sign up to request clarification or add additional context in comments.

2 Comments

console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+grouplist); am getting [object object] what it mean??
@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({}).
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/

1 Comment

console.log("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"+grouplist); am getting [object object] what it mean??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.