JSFiddle - React, Tailwind, and code Playground
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.js"></script>
</head>
<body>
<input name="txtName" type="text" id="txtName" />
<input type="submit" name="btnSave" value="Save" id="btnSave" />
</body>
</html>
JavaScript
$('#btnSave').click(function(e)
{
var reportRecipients = "A,a, a, a ,";
checkDuplicate(reportRecipients );
});
function checkDuplicate(reportRecipients )
{
if (reportRecipients.length > 1)
{
var recipientsArray = reportRecipients.split(',');
var newUniqueArray = [];
alert('Expected Alert 1');
for (a in recipientsArray)
{
var email =$.trim(recipientsArray[a]);
if ( $.inArray(email,newUniqueArray) == -1 )
{
newUniqueArray.push(email);
}
}
alert('Expected Alert 2');
return false;
}
}