Wheelnut
0
Q:

ruby does object exist in array

# 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/)
0

New to Communities?

Join the community