Ruby Does Object Exist In Array

[Solved] Ruby Does Object Exist In Array | Ruby - Code Explorer | yomemimo.com
Question : ruby does object exist in array

Answered by : braden

# Element exists in array
object_exists = arr.any? { |elem| elem == desired_value }
# Element with property exists in array
object_exists = arr.any? { |obj| obj.prop == desired_value }
# Type exists in array
object_exists = arr.any?(Integer)
# Element matching regex exists in array
object_exists = arr.any?(/d/)

Source : https://apidock.com/ruby/Enumerable/any%3F | Last Update : Fri, 27 Nov 20

Answers related to ruby does object exist in array

Code Explorer Popular Question For Ruby