在数组中查找值 [英] Find value in an array
本文介绍了在数组中查找值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Ruby 中,如何在数组中查找值?
In Ruby, how can I find a value in an array?
推荐答案
如果您正在尝试确定数组中是否存在某个值,您可以使用 Array#include?(value):
If you're trying to determine whether a certain value exists inside an array, you can use Array#include?(value):
a = [1,2,3,4,5]
a.include?(3) # => true
a.include?(9) # => false
如果您有其他意思,请查看 Ruby Array API
If you mean something else, check the Ruby Array API
这篇关于在数组中查找值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文