Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have an Array with an Object with multiple Objects in them with the use of Vue.js.

See it like this:

tree: [{
  stick: {
    leaf:{
      name: "Vincent"
    },
    sheet:{
      name: "Charles"
    },
    paper:{
      name: "Harry"
    }
  }
]}

Now my question is: How do I reach the name of a leaf?

share|improve this question

This could not work. You set the leaf property multiple times which is not supported. I assume you would do something like:

var myvar = {stick: [
  {leaf: {name: "Vincent"}}, 
  {leaf: {name: "Charles"}},
  ...
]};

console.log(myvar.stick[0].leaf.name);
share|improve this answer
    
I have changed the array so that leaf is unique, but the focuspoint in my question was how I could reach data nested in an object, nested in an object, nested in an array. – Inbar Azulay Oct 11 at 12:53
    
For my example: myvar.stick[0].leaf.name – Psi Oct 11 at 12:55
    
Yes, but in your example stick is an array and not an object – Inbar Azulay Oct 11 at 13:05
    
exactly! This is why i use the stick[0] notation which references the 0th elem in the array – Psi Oct 11 at 13:07
    
Yes, okay... But my data is recursive, so I don't always want the first object in the array. Maybe you can look to this link/. Here is my HTML-code. – Inbar Azulay Oct 12 at 7:34

You'd want tree[0].stick.leaf.name with the data you have.

share|improve this answer
    
Thanks, but how can I call the name with my HTML-code? Putting this between curly brackets doesn't help – Inbar Azulay Oct 11 at 13:26
    
That's not true: jsfiddle.net/crswll/5sH6A/768 – Bill Criswell Oct 11 at 13:44
    
Are you working in a loop? I find this situation a little weird and think you need to give more details. – Bill Criswell Oct 11 at 13:45
    
Yes, the API is recursive thus I need to loop through the array. If you check out this link, you'll see snippets of my code: forum.vuejs.org/t/2-errors/1273 – Inbar Azulay Oct 11 at 13:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.