Question: I have a react app in which i need to push new key values (values can be arrays) to a key in state.

```
this.state = {
    keyValue: {}
}

```

Visualising it will be something like this:

`keyValue:{'key1':[value1],'key2':[value2,value3]}`

How do i do this in react ?i tried:

`const newKeyvalue = Object.keys(state.keyValue).map((keyValues) => {
return {...keyValue, key: value};});
this.setState({keyValue: newKeyvalue});`
But this does not work

Answer: 
`keyValue` is a dynamic variable? 
They try the following 

```
this.setState({[keyValue]: newKeyvalue});

```
I'm using like this

```
obj = []
obj.push({ value: i, label:data[i].api_keys_id })

```

result:

```
[
  { value: 1, label: 154 },
  { value: 2, label: 545 }
]

```

if you want to key name dynamic you can wrap with [] and then set

```
obj = []
myKeyName="value"
obj.push({ [myKeyName]: i, label:data[i].api_keys_id })

```