Just wondering is there the same method for an Array object similar to indexOf in JavaScript?
For example:
arr = %w{'a', 'b', 'c'}
c = 'c'
if (arr.indexOf(c) != -1)
// do some stuff
else
// don't do some stuff
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is the
.indexmethod of Array.http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-index
In ruby, only
falseandnilare considered as false value, so you could just do: