I want to add items to an array skipping the duplicates. However for some reason only one item is being added and the second item is not being added. Here is my code.
var add = ['email1@gmail.com', 'email2@gmail.com', 'email1@gmail.com'];
var main_messages = []
var from
function findMessages(messageList) {
return messageList = from;
}
add.map(function(map){
from = map
if(main_messages.find(findMessages) === undefined){
main_messages.push(map)
}
});
console.log(main_messages)
So the expected output should be
['email1@gmail.com', 'email2@gmail.com']
But the output I'm getting in this code is only
['email1@gmail.com']
What am I doing wrong and how can I fix this problem?