I'm trying to understand why this wont work in my EJS template. I basically I have two arrays. One is a full list that I'm looping through and building a select list with. The other array is simply the people that have already been selected. I'm attempting to match these list via a indexOf inside of my for loop, but for some reason the match stops at the first match and doesn't work past that. See below for current set up.
<select id="select-team" multiple="multiple" name="people">
<% for(var i=0; i<names.length; i++) {%>
<option value="<%= names[i] %>"
<% if (currentList.indexOf(names[i]) > -1){%>
selected
<% } %>
><%= names[i] %>
</option>
<% } %>
</select>
On the flip side, I can do this very easily in raw javascript. Is this a limitation of EJS? Is there a better way to handle this? Fiddle is provided below to show it currently working with vanilla JS.
https://jsfiddle.net/f8e401L9/7/
var name = ['A','B','C','D','E','F','G','H'];
var chosen = ['A','F','G','H'];
for (var i = 0; i < name.length; i++) {
if (chosen.indexOf(name[i]) > -1) {
console.log('selected');
}
}
