Jquery check if array contains duplicate string -
how check if array contains duplicate string , have validatearray = ['sa','sa','yu'] have used following function same not working me.
checkduplicate = function (reportrecipients) { if (reportrecipients.length > 1) { var recipientsarray = reportrecipients.tostring().split(','); (a in recipientsarray) { if(reportrecipients.indexof(a) != reportrecipients.lastindexof(a)){ return true; break; } } } return false; }
this working me:
var reportrecipients = ['aaa', 'xyz', 'aaa', 'abc', 'xxx', 'xyz', 'pqr']; var recipientsarray = reportrecipients.sort(); var reportrecipientsduplicate = []; (var = 0; < recipientsarray.length - 1; i++) { if (recipientsarray[i + 1] == recipientsarray[i]) { reportrecipientsduplicate.push(recipientsarray[i]); } }
hope helps.
Comments
Post a Comment