title: how to add value to array of objects to a particular Index in React
body: <p>I want  add data to array of object on button click, if index value not present create new object and add data</p>
  <pre><code>const [sampleArray, setSampleArray] = useState([{fruit:'', Vegetable:''}])
  
  const addData=(index, value)=&gt;
  {
      setSampleArray()
  }
  </code></pre>
  <pre><code>
  on first click :  index = 1 &amp; fruit = 'orange'
  on second click :  index = 1 &amp; vegetable = 'brinjal'
  on third click :  index = 2 &amp; fruit = 'Banana'
  on fourth click :  index = 2 &amp; fruit = 'cabbage'
  
  &lt;button onClick={addData}&gt; submit &lt;/button&gt;
  
  </code></pre>
  <p>result should be like this:</p>
  <p>[{fruit:'orange', Vegetable:'brinjal'}, {fruit:'Banana', Vegetable:'cabbage'}]</p>
  <pre><code></code></pre>