Home > Enterprise >  How to delete a single object from an array of objects?- React JS
How to delete a single object from an array of objects?- React JS

Time:11-15

I have an array of objects. The object contains two enteries I want to delete one entry and refresh the page with only one entry loading on the page. result I'm getting

CodePudding user response:

`function deleteItem(id) { setAllStandups((prevStandup)=>{

  return prevStandup.map((standup) => {
      if(standup.yesterday.id === id){
          return {...standup.today}
      }
    else{
    return {...standup.yesterday};
    }
  });
})

}`

this will delete only clicked value.

CodePudding user response:

It is not array, It should be deleting the node from JSON Object.

 function deleteItem(NodeName,precStandup) {
        delete precStandup[NodeName];
        return precStandup; 
      }
    let result=deleteItem("yesterday",standup);
  • Related