title: Select option Onchange method- if the object is there then update it or else create a new one
body: <pre><code>const [skills,setSkills] = useState([
      {
        name:&quot;&quot;,
        skill_type:&quot;&quot;,
        level_type:&quot;&quot;
      }
    ])
  
   const handleChangeSkillType =(e,index)=&gt;{
      const primary = e.target.getAttribute('dataskill')
      const newstate=skills.map((skill)=&gt; skill.name === primary ? {...skill,skill_type:e.target.value} : {name:primary,skill_type:e.target.value,level_type:&quot;&quot;} )
      setSkills(newstate)
    }
  
  
  ------return statement---------
  
  {step1response.skills.must_have.slice(0, 5).map((t,index) =&gt; (
                  &lt;tr key={t}&gt;
                    &lt;td&gt;
                      &lt;input type=&quot;checkbox&quot; onChange={(e)=&gt;handleSkills(e,index)}/&gt;
                    &lt;/td&gt;
                    &lt;td value={t.name}&gt;{t}&lt;/td&gt;
                    &lt;td&gt;
                      &lt;select name=&quot;skill_type&quot; dataskill={t} value={t.type} className=&quot;custom-input p1&quot; onChange={(e)=&gt;handleChangeSkillType(e,index)}&gt;
                        &lt;option&gt;Select&lt;/option&gt;
                        &lt;option value=&quot;Must Have&quot; selected&gt;Must have&lt;/option&gt;
                        &lt;option value=&quot;Nice to have&quot;&gt;Nice to have&lt;/option&gt;
                      &lt;/select&gt;
                    &lt;/td&gt;
  
  </code></pre>
  <p>I am trying to fill up my skills array...In onchange method i want if there is a skill name that matches the attribute in select then update the skill_type or else create a new one...but my on change method is not working as planned...can someone tell what is wrong in this?</p>