Shachy Rivas Shachy Rivas - 2 months ago 8x
Jade Question

How to pass array of objects to jade display in view?

I am using a twitter node module to retrieve searches using the api and putting them into an array of objects stored in a variable called "tweets" that looks like this:

[ { created_at: 'Sun Jul 24 20:32:34 +0000 2016',
text: '2 Timothy 1:7 #nofear #power #love #sound-mind',
{ id: 90281227,
name: 'Anavella',
screen_name: 'anavellar' } },
{ created_at: 'Sun Jul 24 20:32:34 +0000 2016',
text: '


You need not use stringify while passing your context data to your view:

res.render('index', { title: 'Express', data: tweets });

Now, in your jade, you can simply iterate through the array and print the object's properties using dot notation or square bracket notation like we normally do:

block content
  h1= title
  p Welcome to #{title}
    each tweet in data
        li= tweet.text