Filter 2 arrays to see if there is a duplicate

Im wondering how you compare 2 arrays to see weather or not there is a duplicate within that array

 const result = this.specialRange.filter(d => !dayMonth.includes(d));

What ive tried just returns the entire array back to me which i dont want I just want to see is there a duplicate yes -> do something no -> Dont

   var dayMonth: any[] = ["1201","1202","1203","1204",1205"];
   specialRange: any[] = ["1201","1202","1203","1204"];

It either returns the entire special range or daymonth depending what the leading argument is I just want a simple true/false equivalent if there is a duplicate

Both arrays are formatted to have similar values despite being of type Any
This is just for practical learning purposes at the moment

the values always follow something like "1201,1202,1203,1204" So MM/DD

Edit for Pyth:

On test:

dayMonth = 1215,1216

specialRange = 1215,1216,1217,1218,1219,1220,1221,1222,1223,1224,1225,1226,1227,1228,1229

Adapted method:

for(let v of dayMonth){


Result => False/False

for some reason my console doesnt log anything when I use console.log

93 thoughts on “Filter 2 arrays to see if there is a duplicate”

  1. Having read your posts about Website Traffic, I believed you have given your readers valuable information. Feel free to visit my website and I hope you get additional insights much as I did upon stumbling across your site.


Leave a Comment