well all answers suggest some kind of spatial partitioning
the most easiest way of doing such a thing is I think a simple 2d grid.(start with cells about 10x10 the size of your average entity)
that way your entities are within a smaller part of the total world.
your current solution does
for(var i = 0; i<400; i++)
for(var j = 0; j<400; j++)
check collision between entity[i] && entity[j];
thats 160000 checks every frame
when you use some kind of space partitioning you can lower that amount drastically.
if you would subdivide your world in for example 8 x 8 large cells you can do this
for(var x = 0; x<8; x++)
for(var y = 0; y<8; y++)
// test all agents in this cell to see if they are colliding with anything in this cell
// if the agents are distributed evenly, (unlikely but for the example it's nice)
// you have a list with entites here that's 400/(8x8) = 6 long.
// that means you will test those 6 with each other.
for(var i = 0; i<6; i++)
for(var j = 0; j<6; j++)
check collision between entity[i] && entity[j] in cell[x,y];
now you have a total of (6x6) * (8x8) = 2304 checks
compared to 160000 thats a very big gain.
to be fair; you would also need to check neighbouring cells to see if a collision exists between entities that are both in another cell, but still you will have gained a factor few dozen.
you can play about with the cell sizes too, and when you get this technique it's easier to look into the more advanced techniques if you would still need more power.
edit: your questions look as if you try to optimize the collision checking method.
the reason why your code is slow is not the actual check, it's the amount of checks you do!