title: Unable to remove objects from array , react.js
body: <p>I'm trying to remove an item from a <code>childArray</code> that is nested into another Array.</p>
  <p>This is How I'm trying.</p>
  <pre><code>const childArrayHandler = (childData, sub, questionId, data, btnId) =&gt; {
      // Manage color change on click
      const isInList = selectedBtnList.some((item) =&gt; item === btnId)
      if (isInList) {
        onSelectedBtnListChange(selectedBtnList.filter((item) =&gt; item !== btnId))
      } else {
        onSelectedBtnListChange([...selectedBtnList, btnId])
      }
  
      // Manage childData Array 
      // copy data to mutable object
      const currentChildData = [...childData]
      const hasId = currentChildData.find(({ id }) =&gt; sub.id === id)
  
      if (!hasId) {
        // add item to childArray if same index is not available in the childArray
        const newChild = { id: sub.id, sub_question: sub.sub_question, weightage: sub.weightage }
        currentChildData.push(newChild)
        setChildDataOnChange((current) =&gt; [...current, newChild])
      } else if (hasId) {
        // remove item from childArray if same index is available in the childArray
        const indexOfChild = currentChildData.indexOf(hasId)
        // console.log('currentChildData', currentChildData, 'indexOfChild', indexOfChild)
        currentChildData.slice(indexOfChild, 1)
        setChildDataOnChange(currentChildData)
      }
  
      const newData = [...data]
  
      // find parent of the child
      const parent = newData.find(({ parentId }) =&gt; questionId === parentId)
  
      // find index of parent
      const indexOfParent = newData.indexOf(parent)
      // update data with child related to parent
      newData[indexOfParent].child = currentChildData
      onDataChange(newData)
      localStorage.setItem('deviceReport', JSON.stringify(newData))
    }
  </code></pre>
  <p>The problem is in the <code>else if</code> block, I want if there's an index of object available in the child then it should remove it from the array. As far as I can see I'm using the correct approach as other articles suggested to handle but missing something which I cant see right now. But not able to find the proper result. If I console it doesn't change anything. means don't remove any item from the array if the index is already is there.</p>
  <p><strong>So how can I fix this, or what might be doing wrong, is there any other way to do it please also mention it?</strong> Thanks</p>