I've created an example for you to have a look at, it finds all of the duplicate IDs within a form/element on a page and prints the duplicates ID names to the console.
The array contains
method was taken from this post.
The above code will output the following:
Duplicate: a
Duplicate: d