Find a match in two dimensional array?

Find a match in two dimensional array?

I have an array in the following format.

test =[  [id:1,subject:math],  [id:2,subject:math],   [id:1,subject:science], ]

what i basically want is when i am trying to push a new object in my array , i should check if the id subject pair already exits like [id:1,subject:math] should be inserted. So basically unique pairs are only to be allowed. Hwo can i loop through this test array to find if a match exits.

Thank you in advance.