# Loop over object properties to create buttons in visualization

**URL:** <https://discuss.elastic.co/t/loop-over-object-properties-to-create-buttons-in-visualization/207840>\
**Category:** Kibana\
**Created:** [November 14, 2019, 9:02am UTC](https://discuss.elastic.co/t/loop-over-object-properties-to-create-buttons-in-visualization/207840 "2019-11-14T09:02:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elaak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elaak/32/55014_2.png) [@Elaak](https://discuss.elastic.co/u/Elaak)\
**Post date:** [November 14, 2019, 9:02am UTC](https://discuss.elastic.co/t/loop-over-object-properties-to-create-buttons-in-visualization/207840/1 "2019-11-14T09:02:28Z")

</div>

I am creating a react visualization plugin that lists a couple of buttons. In my react component I have access to a configurable object with X properties. I want to loop over those properties and create a button for each entry, but somehow I can't seem to get it working.

This is my render function:

```
render() {
  return (
    <EuiPage>
      <EuiPageBody>
        <EuiPageContent>
          <h3>List of buttons</h3>
          {Object.keys(this.listData).forEach(function (key) {
            return <button className="myBtn" onClick={() => this.processElement(key)}>{key}</button>
          })}
        </EuiPageContent>
      </EuiPageBody>
    </EuiPage>
  )
}

```

I have checked that `key` has the right values, but in Kibana I never see any buttons appearing, nor any error. What am I missing?

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [November 19, 2019, 1:33pm UTC](https://discuss.elastic.co/t/loop-over-object-properties-to-create-buttons-in-visualization/207840/2 "2019-11-19T13:33:41Z")

</div>

`forEach` does nothing with the return value of the iterator function, you need to use `map`. It's basically the same with the difference that it uses the return values to build a new array which is subsequently passed to react. Otherwise your render function looks fine.

---

<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:** [December 17, 2019, 1:33pm UTC](https://discuss.elastic.co/t/loop-over-object-properties-to-create-buttons-in-visualization/207840/3 "2019-12-17T13:33:51Z")

</div>

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