I assume your rectangles
are represented by objects.
The bad news:
Yes, you must use loops to hit-test each rectangle object against every other rectangle object.
The good news:
Modern browsers are very fast.
So start by coding your nested loops to hit-test all combinations of rectangles.
If the results are sluggish, look at this post which examines how to divide the canvas into subsections so that only those rectangles in a subsection need be tested against each other. The post uses java, but you can "see-it-in-c#" fairly easily.