The below given state is in my class component. Need to avoid adding duplicate objects in an array my state is given below
this.state = {
frequency: {
time: [
{time:"20:15",timezone:"IST"},
{time:"01:30",timezone:"UST"}
],
},
};
the requirement is sholud not add the object with same time and timezone value. my push code is given below
this.setState((state) => ({
...state,
frequency: {
...state.frequency,
time: [...state.frequency.time, selecttime],
},
)}
))
the selecttime which carries the object which im going to push in the time array
const selecttime = {time:"20:15",timezone:"IST"}
i should not adding same object again. how do i avoid pushing duplicate objects in state array
array.findto check if same entry exists, its not a react question