I am trying to render an array and apply filtering in EJS.
I would like to loop over the array and sort ascending by name.
The docs do not give much straightforward info about filtering methods
View:
<select>
<% for( var i=0; i < genres.length; i++){ %>
<option value="<%=: genres[i].name | sort_by:'asc' %>"><%= genres[i].name %></option>
<% }; %>
</select>
Service:
var express = require('express'),
ejs = require('ejs');
const genres = [{ name: 'action' }, { name: 'fiction' }, { name: 'thriller' }];
ejs.filters.sort_by = function() {
console.log(genres)
};
Err:
SyntaxError: Unexpected token ':'