Search code examples
javascriptobjectmustache

Mustach loop through Obj containing Array containing Obj


I have an Object containing Arrays containing Objects
Example:

main: {
  arr1: [
    obj1: {x: 0, y: 0},
    obj2: {x: 0, y: 0}
  ],
  arr2: [
    obj3: {x: 0, y: 0},
    obj4: {x: 0, y: 0}
  ]
}

I need with Mustach to retrieve all the x values of those objects (obj1 - 4).
Every object and array can have a random name.

I tried:

{{#main}}
  {{#.}}
    {{x}}
  {{/.}}
{{/main}}

But it's not working.
Anyone have an idea?

Thanks


Solution

  • If I'm not mistaken, when a section refers to an object, the properties of the object are exposed inside the section, but there is not iteration. So in the section {{#main}}, arr1 and arr2 are exposed, and {{#arr1}} would iterate the array.