Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering if there was a more elegant way of finding whether an element exists in an N-dimensional array. The way I would do it is:

 inArrayQ[a_,el_] := If[Length@Position[a,x_/;x==el]==0,False,True];

But this seems rather cumbersome. I am surprised there is no built-in Mathematica function that does this, but if not, is there a better way to write such a function?

share|improve this question
check out MemberQ – Pinguin Dirk Sep 20 '13 at 20:07
D'oh, if only the documentation search was better...thanks. – Guillochon Sep 20 '13 at 20:08
@Guillochon If you search for MemberQ you get the answer right away ;) – Dr. belisarius Sep 20 '13 at 20:31
@Guillochon You can also use Position to determine where the element is. – RM1618 Sep 22 '13 at 10:40
up vote 2 down vote accepted

Not to have any more open, unanswered questions

Check out MemberQ, you should find all information there.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.