0

I have created this object :

    var hemicycle = {

    Groupe : "Group1" [{
        Member : [{
            Name : "MemberName",
            Siege : "SiegeNumber",
            Vignette : "PhotoURL"
        }]

    }]


};

I try to display some data from it but I can't access any. When I type hemicycle in the dev tools of Chrome I get this :

enter image description here

I also tried to display "Group1" from the object but it won't let me, I typed this :

enter image description here

I don't know why my object is not defined ?

Any help is appreciated.

3
  • JavaScript (MDN). Working with Objects (MDN) Commented Oct 26, 2017 at 12:37
  • 2
    Remove "Group1" (it's not valid declaration) should work. Commented Oct 26, 2017 at 12:37
  • 3
    Your object is invalid. Your Groupe should be object, but is like simple value, no : after Group1... Commented Oct 26, 2017 at 12:37

3 Answers 3

2

Well, the issue is, that you actually don't have a valid object. Groupe has really weird structure, what is it supposed to be? Array? Then try this:

var hemicycle = {
  Groupe: [{
    Member : [{
      Name : "MemberName",
      Siege : "SiegeNumber",
      Vignette : "PhotoURL"
    }]

  }]
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I removed "Group1" and create a GroupName : "Group1" inside of Groupe. Working great right now !
2

Your problem is that your object itself is invalid. Two ways to improve that. Choose whatever fits your needs best.

var hemicycle = {

Groupe : "Group1",
Content : [{
    Member : [{
        Name : "MemberName",
        Siege : "SiegeNumber",
        Vignette : "PhotoURL"
    }]

}]

};

var hemicycle = {
    Groupe : [{
        Member : [{
           Name : "MemberName",
           Siege : "SiegeNumber",
           Vignette : "PhotoURL"
    }]

}]

};

2 Comments

Thanks, I managed to modify my array with the answer of Paulooze.
the most important thing is that you have learned something, not to whom the repu goes :D
0

this simple example should solve your problem

var myObj = {
    "1": { address: "44 buxton gardens berea durban", lat: "25.686", lng: "58.1156"},
    "2": { address: "44 buxton gardens berea durban", lat: "0.0086", lng: "-0.00056"}
 }

  alert(myObj['1']['address']); //this get the address value of the first element

//using foreach statement to access the element and key

 for (key in myObj){
  alert(key); //this will display the 1
 //use can say
 alert(myObj[key]['address']); // this gets the value of address
 }

Comments

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.