What a lot of answers and I've not seen one that exploits the sort function itself to build the list of duplicates as the original list is sorted. The top answer is order n + n log n. This answer is order n log n.
a = [1,7,2,3,4,5,6,1,4];
dups=new Set();
a.slice().sort((a,b)=>{if(a<b) return -1; else if(a>b) return 1; else {dups.add(a);return 0}});