mercredi 25 septembre 2019

How to remove element from array after uncheck of checkbox

I am having multiple locations, on check of the particular location i can able to push those into array on check of checkbox unable to remove from array

handleChange(e){
    if(e.target.checked){
        let selectedLocations = this.state.selectedLocations;
        selectedLocations.push({
            name: e.target.name,
            isActive: true
        });
        this.setState({
            selectedLocations: selectedLocations
        });
    }else{
        let selectedLocations = this.state.selectedLocations;

    }


}

{
 locations && locations.map((el, i) => {
   return (
         <div className="col-md-4">
         <div className="form-group">
         <input type="checkbox" value="true"  name={el.name} onChange={this.handleChange.bind(this)}/><label> &nbsp;{el.name} </label>
      </div>
  </div>
 )
})
}

I want to remove from array after unchecking particular location




Aucun commentaire:

Enregistrer un commentaire