C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: The include method returns true if a value if found. If a value is not found, it returns false.
Next: The program searches the "values" array for 999, which is not found. It prints a helpful message.
Ruby program that uses include method on array
values = [10, 200, 3000]
# See if array includes this value.
if values.include?(200)
puts "ARRAY CONTAINS 200"
end
# See if array does not include this value.
if !values.include?(999)
puts "ARRAY DOES NOT CONTAIN 999"
end
Output
ARRAY CONTAINS 200
ARRAY DOES NOT CONTAIN 999