In my code I need to find the repeated value and give an alert using jQuery. Below is the example arrays and my requirement. Please help.
a1 = {1,2,3,4,5,6,4}
a2= {9,8,7},
a3= {a,b,c,d,e,7}
In the above arrays I need to get the value 4 and give alert because it is repeating in array "a1" and I need to get the value 7 because it is repeating in the arrays 'a2' and 'a3'.
The first issue I fixed like as follows. Ineed to to fix the second one.
for (var $i = 0; $i<= $last; $i++)
{
var hours = [];
var minutes = [];
var activeTime = [];
$.each($('.hour'+$i),function() {
hours.push($(this).val());
});
$.each($('.hour'+$i).next('select'),function(){
minutes.push($(this).val());
});
for ( var i = 0; i < hours.length; i++ ) {
activeTime.push(hours[ i ]+":"+minutes[ i ]+":"+"00");
}
for ( var i = 0; i <= hours.length; i++ ) {
if ( hours[ i ] === "" )
{
$("#timeValidate"+$i).css("display", "block");
return false;
}
else
{
$("#timeValidate"+$i).css("display", "none");
}
}
for(var i=0; i< activeTime.length; i++)
{
for(var j = 0; j< activeTime.length; j++)
{
if( i != j)
{
if(activeTime[j] == activeTime[i])
{
$("#timeValidate"+$i).text("");
$("#timeValidate"+$i).text("active time"+activeTime[j]+" is repeating");
$("#timeValidate"+$i).css("display", "block");
return false;
}
}
}
}
}
concatyour arrays before checking for duplicates. That way you don't have to care about whether or not the duplicates are in different source arrays.