> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/search_a_list.md).

# Search a list

```ruby
var haystack = %w(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo)
 
%w(Bush Washington).each { |needle|
    var i = haystack.first_index{|item| item == needle}
    if (i >= 0) {
        say "#{i} #{needle}"
    } else {
        die "#{needle} is not in haystack"
    }
}
```

#### Output:

```
4 Bush
Washington is not in haystack at find.sf line 9.
```

Extra credit:

```ruby
var haystack = %w(Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo)
say haystack.last_index{|item| item == "Bush"}
```

#### Output:

```
7
```
