"-6ren">
gpt4 book ai didi

ruby - 如果数组中的对象包含 Ruby 中的所需值,如何获取索引

转载 作者:太空宇宙 更新时间:2023-11-03 17:20:40 25 4
gpt4 key购买 nike

所以这是我从某处获得的数组,我想获得包含“文本”=>“ Assets ”的对象的索引。我如何在 Ruby 中做到这一点?

例子

[{
"class" => "android.support.v7.widget.AppCompatTextView",
"tag" => nil,
"description" => "android.support.v7.widget.AppCompatTextView{b777d8c V.ED..... ........ 0,39-355,168 #7f0e007f app:id/textview_sectiontitle}",
"id" => "textview_sectiontitle",
"text" => "Assets",
"visible" => true,
"rect" => {
"height" => 129,
"width" => 355,
"y" => 2088,
"x" => 80,
"center_x" => 257,
"center_y" => 2152
},
"enabled" => true,
"contentDescription" => nil
},
{
"class" => "android.support.v7.widget.AppCompatImageButton",
"tag" => nil,
"description" => "android.support.v7.widget.AppCompatImageButton{ae57704 VFED..C.. ........ 1056,0-1280,208 #7f0e0109 app:id/imagebutton_amount}",
"id" => "imagebutton_amount",
"visible" => true,
"rect" => {
"height" => 208,
"width" => 224,
"y" => 2049,
"x" => 1136,
"center_x" => 1248,
"center_y" => 2153
},
"enabled" => true,
"contentDescription" => nil
}]

最佳答案

试试这个

arr.index { |item| item["text"] == "Assets" }

关于ruby - 如果数组中的对象包含 Ruby 中的所需值,如何获取索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44694217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com