# Ruby get element of an array

**URL:** <https://discuss.elastic.co/t/ruby-get-element-of-an-array/152004>\
**Category:** Logstash\
**Created:** [October 11, 2018, 8:05am UTC](https://discuss.elastic.co/t/ruby-get-element-of-an-array/152004 "2018-10-11T08:05:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre2](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@Pierre2](https://discuss.elastic.co/u/Pierre2)\
**Post date:** [October 11, 2018, 8:05am UTC](https://discuss.elastic.co/t/ruby-get-element-of-an-array/152004/1 "2018-10-11T08:05:44Z")

</div>

Hello,

I want to get the element of an array called 'Choix menu SVI' at the position "i" and check if it is equal to '9'. I tried this bit it does not work. How can I do that ?

> if(event.get('Choix menu SVI'[i]))=='9'  
> event.set('Motif','Joindre';  
> end

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [October 11, 2018, 10:12am UTC](https://discuss.elastic.co/t/ruby-get-element-of-an-array/152004/2 "2018-10-11T10:12:13Z")

</div>

Try this one

```auto
if event.get('Choix menu SVI')[i] == '9'
  event.set('Motif','Joindre')
end
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 8, 2018, 10:19am UTC](https://discuss.elastic.co/t/ruby-get-element-of-an-array/152004/3 "2018-11-08T10:19:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
