Datsik
Datsik

Reputation: 14824

How can I iterate a multi-dimensional array with Jade template lang

I'm wondering if it is possible to iterate a multi-dimensional array, in Node.js I'm returning an array that has an object inside of it, and I'm putting it into an array so that I can push to it, but when it is all done pushing, I'm left with something like

[ [
   {
     stuff: stuff
   }
  ],
  [ 
   { 
    stuff: stuff
   }
  ]
]

I tried

each item in items
  p= item

which returns [object Object]

When I try

each item in items
  p= item.invdescription

I get an error, any idea how I can do such a thing with Jade? Thanks!

Basically:

for (var i = 0; i < items.length; i += 1) {
  p= items[0][i].invdescription
}

Upvotes: 7

Views: 5830

Answers (1)

Mithun Satheesh
Mithun Satheesh

Reputation: 27845

if items is having the value

[ [
   {
     stuff: stuff
   }
  ],
  [ 
   { 
    stuff: stuff
   }
  ]
]

then you can iterate over the stuff values in jade via

each item in items
     p #{item[0].stuff}

Upvotes: 7

Related Questions