How to apply rules to only certain elements in array

The worm

I have this loop in react:

<div>
   {this.state.dealersDeck.map(function(card, index){
      return <div className="cardFormatDH" key={ index }> {card.rankKey}{card.suit} </div>;
   }, this)}
</div>

This goes through an array of objects and then renders them on screen. This is all good except I would like to format it so I only display the contents at certain points. i.e. I'm creating blackjack and I don't want the dealers second card to be visible until the end.

I may have to show more code but was wondering if map had some sort of attribute that I could use.

Abhinav

You can use basic If...Else statements inside map function as well. Moreover you can write more business logic also to add more functionality.

var cardsHTML = this.state.dealersDeck.map(function(card, index){

    if(condition...1){
        return <div className="cardFormatDH" key={ index }> {card.rankKey}{card.suit} </div>
    }

    if(condition...2){
        return <div></div>
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Array Only Prints Certain Elements and Not Others

How to count certain elements in array?

What's the fastest way to only rotate certain elements in an array?

Make ESLint apply rules to only certain file name patterns

How to replace only the first n elements in a numpy array that are larger than a certain value?

jQuery how to removeClass of only certain elements

How to apply a css tooltip only to a certain element?

How to apply background to specific elements only?

in vimrc apply certain highlighting rules only for certain filetype

How to remove certain elements from an array into a new array and leave the others only the original array?

How to apply style to an array of SVG elements

How to access certain elements in Matlab structure array

How to get certain elements of an array in laravel?

Return only elements of an array in an object that contain a certain value

How to apply CSS rules after a certain tag

Write only certain elements / columns of a 2 dimensional array back to worksheet

How to count certain elements in an object array in JavaScript?

How to apply Fourier transform to extract the frequency of only certain edges in an image?

Overflow only certain elements

CSS font family only apply to certain elements within the same class

Permute only certain elements in an array in python

How to apply a function for the first certain elements of an array in Scala?

Initialize only certain elements of array in dzn file

How to apply CSS only on certain anchors

How to apply $lt to array elements?

How to define a function that returns an array of elements which can vary in types but all must conform to certain protocol rules?

How to pick only certain elements from an array in Ruby?

Apply font-size to only certain child elements

How to access only certain elements in a 2d array in Javascript?