I have the following state value as an array. How can I push a new list var newList into Students array where the key Students is dynamically generated and sometimes it might be pushing to Teachers array.
The current list is available at
let key = "Students"
console.log(this.state.school[key])
My state is following and I need to push the new array of students or teachers based on the key.
this.state = {
school: {
Teachers: [
{
id: "1",
name: "T1",
},
{
id: "2",
name: "T2",
}
],
Students: [
{
id: "1",
name: "S1",
},
{
id: "2",
name: "S2",
}
]
}
}