title: store and update associative array in state react js
body: <p>How to update my associative array while the key already exists else I want to create a new key and store that array in the state. I had tried to store a value in the associative array.
  When I entering data in the input field it can call <code>handleChange</code> after that I want to do that above I mentioned operations</p>
  
  <pre><code>    import React, { Component } from 'react';
  
          class App extends Component {
              constructor(props) {
                  super(props);
                  this.onChangeEvent = this.onChangeEvent.bind(this);
                  this.onChangeCount = this.onChangeCount.bind(this);
                  this.onSubmit = this.onSubmit.bind(this);
                  this.state = {
                      name: [],
                      inputCount:5
                  }
              }
  // associtive array
          handleChange = (e) =&gt; {
  // I want to check the key is already exist or not if exist means create update the value else create a new key and also I want to validate all the data.
                      const check = e.target.name
                      const value = e.target.value
                      const name = []
                      name[check] = value
                      console.log(name)
                      this.setState({
                          name,
                      })
              }
          render() {
                  let options = []
                  for (let i = 0; i &lt; this.state.inputCount; i += 1) { options.push(i); }
              return (
  {this.state.inputCount &amp;&amp; (
                          options1.map((i) =&gt; {
                              return (&lt;div key={i}&gt;
                                  &lt;input  onChange={this.handleChange} type="text" className="name" name={`name${i}`} placeholder="Name" /&gt;&lt;br /&gt;
                              &lt;/div&gt;)
                          })
                      )}
          );
              }
          }
          export default App;
  </code></pre>