I'm trying to see inline if an array from a mongodb database contains a specific object but I just can't get it to work.
I have been searching all around for different solutions and tried all of them; Array.some, Array.includes, Array.indexOf etc etc.
I'm quiet new to this so I'm probably under some misunderstanding, does anyone have an idea what I'm doing wrong? The app starts as normal and no error messages but it's saying everyone is a "leader" while they are not.
<div class="ui three buttons">
<% if(task.leaders.includes(currentUser)){ %>
<button form="deleteTaskForm" class="ui basic negative button"><i class="ui icon trash alternate"></i></button>
<a class="ui basic orange button" href="/task/<%= task._id %>/edit"><i class="ui icon edit"></i></a> <% }
else{ %>
<div style="opacity: 40%;" class="ui basic negative button popupButton" data-content="Only the leader of the task can remove this task."><i class="ui icon trash alternate"></i></div>
<div style="opacity: 40%;" class="ui basic orange button popupButton" data-content="Only the leader of the task can edit this task."><i class="ui icon edit"></i></div>
<% } %>
<button form="doneTaskForm" class="ui basic green button"><i class="ui icon check square"></i></button>
</div>
Array.prototype.some()
<div class="ui three buttons">
<% if(task.leaders.some(leader => leader._id == currentUser._id)){ %>
<button form="deleteTaskForm" class="ui basic negative button"><i class="ui icon trash alternate"></i></button>
<a class="ui basic orange button" href="/task/<%= task._id %>/edit"><i class="ui icon edit"></i></a> <% }
else{ %>
<div style="opacity: 40%;" class="ui basic negative button popupButton" data-content="Only the leader of the task can remove this task."><i class="ui icon trash alternate"></i></div>
<div style="opacity: 40%;" class="ui basic orange button popupButton" data-content="Only the leader of the task can edit this task."><i class="ui icon edit"></i></div>
<% } %>
<button form="doneTaskForm" class="ui basic green button"><i class="ui icon check square"></i></button>
</div>
EDIT: Solved. This is the solution that got it to work for me.
<div class="ui three buttons">
<% if(task.leaders.some(leader => leader._id.equals(currentUser._id))){ %>
<button form="deleteTaskForm" class="ui basic negative button"><i class="ui icon trash alternate"></i></button>
<a class="ui basic orange button" href="/task/<%= task._id %>/edit"><i class="ui icon edit"></i></a> <% }
else{ %>
<div style="opacity: 40%;" class="ui basic negative button popupButton" data-content="Only the leader of the task can remove this task."><i class="ui icon trash alternate"></i></div>
<div style="opacity: 40%;" class="ui basic orange button popupButton" data-content="Only the leader of the task can edit this task."><i class="ui icon edit"></i></div>
<% } %>
<button form="doneTaskForm" class="ui basic green button"><i class="ui icon check square"></i></button>
</div>