# Init value from an Object for a select Input does not work

**URL:** <https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078>\
**Category:** Help\
**Created:** [April 5, 2024, 4:47pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078 "2024-04-05T16:47:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![PBrockmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/pbrockmann/32/1552_2.png) [@PBrockmann](https://talk.observablehq.com/u/PBrockmann)\
**Post date:** [April 5, 2024, 4:47pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078/1 "2024-04-05T16:47:45Z")

</div>

Could someone explain me why the initialisation of a select Input is not possible from an Object ?

```auto
initValue1 = ({ name: "Warriors", location: "San Francisco, California" })

```

```auto
viewof favorite1 = Inputs.select(teams, {
  label: "Favorite team",
  format: (x) => x.name,
  value: initValue1
})

```

See:  
[https://observablehq.com/d/7b0e463acd4a21dc](https://observablehq.com/d/7b0e463acd4a21dc)

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [April 5, 2024, 5:32pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078/2 "2024-04-05T17:32:26Z")

</div>

Your notebook is not public, but…

Try something like

```
initValue1 = teams[0]

```

The issue is that your `initValue1` is not the same object as `teams[0]`; they have the same _value_ but they are not the same object.

---

<div class="post-metadata">

**Author:** ![PBrockmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/pbrockmann/32/1552_2.png) [@PBrockmann](https://talk.observablehq.com/u/PBrockmann)\
**Post date:** [April 6, 2024, 8:12pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078/3 "2024-04-06T20:12:52Z")

</div>

Have set the notebook as public.

Nope, it seems not to work.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [April 6, 2024, 8:17pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078/4 "2024-04-06T20:17:04Z")

</div>

Works for me.

```js
viewof favorite1 = Inputs.select(teams, {
  label: "Favorite team",
  format: (x) => x.name,
  value: teams[1]
})

```

You can also use the **key** option to initialize the selected value if it’s easier.

```js

viewof favorite2 = Inputs.select(new Map(teams.map((t) => [t.name, t])), {
  label: "Favorite team",
  key: "Warriors"
})

```

---

<div class="post-metadata">

**Author:** ![PBrockmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/pbrockmann/32/1552_2.png) [@PBrockmann](https://talk.observablehq.com/u/PBrockmann)\
**Post date:** [April 6, 2024, 8:28pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078/5 "2024-04-06T20:28:51Z")

</div>

Indeed it works with `teams[1]`but not the value itself. That was my question.

```auto
viewof favorite1 = Inputs.select(teams, {
  label: "Favorite team",
  format: (x) => x.name,
  value: { name: "Warriors", location: "San Francisco, California" }
})

```

gives the “Lakers” not the “Warriors”

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [April 6, 2024, 8:29pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078/6 "2024-04-06T20:29:44Z")

</div>

Right, you can’t do that because it’s not the same object, as pointed out above.

---

<div class="post-metadata">

**Author:** ![PBrockmann](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/pbrockmann/32/1552_2.png) [@PBrockmann](https://talk.observablehq.com/u/PBrockmann)\
**Post date:** [April 6, 2024, 8:35pm UTC](https://talk.observablehq.com/t/init-value-from-an-object-for-a-select-input-does-not-work/9078/7 "2024-04-06T20:35:15Z")

</div>

Ok I understand now.  
Thank you very much.
