Check if a value exists in an array in Ruby

Technology CommunityCategory: RubyCheck if a value exists in an array in Ruby
VietMX Staff asked 3 years ago
Problem

I have a value Dog and an array ['Cat', 'Dog', 'Bird'].

How do I check if it exists in the array without looping through it? Is there a simple way of checking if the value exists, nothing more?

You’re looking for include?:

>> ['Cat', 'Dog', 'Bird'].include? 'Dog'
=> true