A strange situation occurs for the second time. Suppose there is an array of objects of this kind:
var a = [ { 'a' : 1, 'b' : 2 }, { 'a' : 3, 'b' : 4 }, { 'a' : 5, 'b' : 4 } ]; In fact, the objects are huge. So I want, for example, to filter an array, taking only objects with b = 4:
<% var b = a.filter( function( filtered ) { return filtered.b === 4; }); %> I get an array of objects b without a zero object of array a:
[ { 'a' : 3, 'b' : 4 }, { 'a' : 5, 'b' : 4 } ]; And here is some kind of anomaly. When I cycle through the elements of an array, I cannot get the properties of the objects:
<% for( index in b ) { %> <%- b[ index ].b %> <% } %> Must get 4 but get emptiness. b [index] .b is of type undefined, but object b [index] is of type object. I am trying to pass an array in other ways:
<% b.forEach( function( bData ) { %> <%- bData.b %> <% }); %> Same. Now I try through .each - ejs swears, there is no such function. Maybe so:
<% var bLenght = b.length; for( var i = 0; i < bLenght; b++ ) { %> <%- b[i].b %> <% } %> No way too.
Why is this happening in ejs template engine? How can I get to the bottom of object properties?
UPDATE
Oh how interesting it turns out ..
<%- JSON.parse( JSON.stringify( b ) ).b %> Get 4. Your comments?
var bLenghtandi < bLength-i < bLength