Hello, I have a structure that is an object that has several arrays as properties.
Example: items: {Dogs: [], Cats: [], ....}
I want to go through these properties comparing each one with a variable with the name and the conincida to save the item that also happened as data in the corresponding property's array. The code that I put saves the items but in all the properties, so it is not filtering by property name. Any suggestions?
class App extends Component {
constructor() {
super();
this.state = {
lists: [], // this holds the name of each list
items: {} // this property names of this object are the names of the lists;
//their values are arrays of the items in each list
};
}
handleAddItem(s) {
//Aqui el codigo que no funciona como deseo
let itemObj = s.ListName;
let items = Object.assign({}, this.state.items);
for(itemObj in items){
if(items.hasOwnProperty(itemObj)){
items[itemObj].push(s);
}
}
this.setState({ items });
}