Add new value to each object in state array with a condition

Solution

getGameImage = async () => {
      for(var key in this.state.deals) {
        let duplicateArray = [...this.state.deals]
        if(this.state.deals[key]['isSteam']) {     
          await this.setGameImage(this.state.deals[key]['game_code'])
          duplicateArray[key].game_image = this.state.imageUrl;
        }
        else {
          duplicateArray[key].game_image = 'https://i.ytimg.com/vi/mYrKAMLbjYA/maxresdefault.jpg';
        }
        this.setState({deals: duplicateArray});
      }
      }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top