'React js/ javascript code refactor for loop/switch
I have following code where I get 4 different attributes, I need to check each if its true and increment the count
var count = 0;
if (props.isApple) {
count += 1;
}
if (props.isOranges) {
count += 1;
}
if (props.isBanana) {
count += 1;
}
if (props.isJackfruit) {
count += 1;
}
console.log(count);
Is there any simple or nicer way of doing this? Any suggestions??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
