tj / ejs

Embedded JavaScript templates for node
4.47k stars 513 forks source link

for...in loop not printing correctly. #222

Closed khatekar closed 8 years ago

khatekar commented 8 years ago

I am using "2.3.4" version.

Here is an example in ".ejs" template and its output

<% var test = ['test1', 'test2', 'test3', 'test4'] for (var id in test) { %><% if (~~id === 0) { %> This Is A Test Title going only Once<% } else { %>   <% } %>

<%= test[id] %>
<%_ } _%> Here is the output >> This Is A Test Title going only Once test1 test2 test3 test4 This Is A Test Title going only Once function () { return this[this.length - 1]; } This Is A Test Title going only Once function (i) { return this[this.length - (1 + i)]; } Not sure if I had a bug here, but why it prints the last two lines, can anyone help please?
khatekar commented 8 years ago

I missed to use "hasOwnProperty". I fixed it.

mde commented 8 years ago

Also, this repo is no longer maintained. v2 of EJS is here: https://github.com/mde/ejs