# Fill dropdown by function node

**URL:** https://discourse.nodered.org/t/fill-dropdown-by-function-node/48407
**Category:** Dashboard
**Created:** [14 July 2021 13:05 UTC](https://discourse.nodered.org/t/fill-dropdown-by-function-node/48407 "2021-07-14T13:05:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![protonmw](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@protonmw](https://discourse.nodered.org/u/protonmw)
#### Post date: [14 July 2021 13:05 UTC](https://discourse.nodered.org/t/fill-dropdown-by-function-node/48407/1 "2021-07-14T13:05:52Z")

</div>

Hello experts!

I'm trying to fill a dropdown but cant get it work! Whats wrong with my code?

```auto
var msg2 = {};

msg2.options = [];

for (let i=0; i<msg.payload.length; i++)
{
    var label = msg.payload[i].Timestamp__OrderStart.toLocaleString()+"; Anzahl: "+msg.payload[i].PartsCount.toString();
    var value = i;
    var s = {label:value};
    
    msg2.options.push(s);
}

return msg2;

```

```auto
{"options":[{"label":0},{"label":1},{"label":2},{"label":3},{"label":4},{"label":5},{"label":6},{"label":7},{"label":8},{"label":9}],"_msgid":"82856354.20b3"}

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [14 July 2021 13:37 UTC](https://discourse.nodered.org/t/fill-dropdown-by-function-node/48407/2 "2021-07-14T13:37:31Z")

</div>

> [@protonmw](#):
>
> `var s = {label:value};`

try `var s = {[label]: value};`  
Javascript interprets label as a string key not a var, the square bracket tells it to treat it a a variable.

---

<div class="post-metadata">

### Author: ![protonmw](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@protonmw](https://discourse.nodered.org/u/protonmw)
#### Post date: [14 July 2021 13:40 UTC](https://discourse.nodered.org/t/fill-dropdown-by-function-node/48407/3 "2021-07-14T13:40:08Z")

</div>

Thats it! Thanks!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [28 July 2021 13:40 UTC](https://discourse.nodered.org/t/fill-dropdown-by-function-node/48407/4 "2021-07-28T13:40:19Z")

</div>

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