1

Here is the code in nodejs(express):

      response.redirect('file',{test: [{name:'sarah',arr:[1,2,3]},{name:'beck',arr: [2,3,4]}]

Now I want to access the 'arr' for every name in the array of objects.In ejs file:

      <% test.forEach(index,item){ %>
       <p><%= item.arr %></p>
       <% }) %>

This is printed as 1,2,3 and 2,3,4 but I want the answer to be [1,2,3] and [2,3,4].Can someone help?

loksan
  • 157
  • 3
  • 17

1 Answers1

0

You can use a for .. of loop to iterate over all entries of test and then use JSON.stringify on the entries' arr property:

<% for(const testData of test){ %>
<%= JSON.stringify(testData.arr) %>
<% } %>
eol
  • 23,236
  • 5
  • 46
  • 64