1

So this is an array I get from somewhere and I wanted to get the index of the object that contains "text" => "Assets". How can i do that in Ruby?

Example

[{
                     "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
    }]
1

1 Answer 1

6

Try this one

arr.index { |item| item["text"] == "Assets" }
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I'm gonna try your answer.
My pleasure Sir :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.