Get state value by a dynamic key in react

Viewed 27227

Let's say in my component I set the state like so:

this.setState({
      test: "value",
      othertest: "value"        
});

If, elsewhere in my code, I have an array containing the keys for these values, ie- keys = ["test", "othertest"] how can I loop through this array to find the value of the corresponding state value?

2 Answers
Related