How to check if array contains a duplicate string , i have validateArray = [\'sa\',\'sa\',\'yu\'] i have used the following function from SO but same not working for me.
This is working for me:
var reportRecipients = ['AAA', 'XYZ', 'AAA', 'ABC', 'XXX', 'XYZ', 'PQR'];
var recipientsArray = reportRecipients.sort();
var reportRecipientsDuplicate = [];
for (var i = 0; i < recipientsArray.length - 1; i++) {
if (recipientsArray[i + 1] == recipientsArray[i]) {
reportRecipientsDuplicate.push(recipientsArray[i]);
}
}
Hope that helps.