Reputation: 1372
How can one assign to a an object which has a boolean property random values of true or false?
items: any[];
items.forEach( (item) => {
item.randomBooleanProperty = ...; //true of false
});
Upvotes: 1
Views: 1561
Reputation: 390
You can try this example: In this code, we check whether the random number which is between 0 and 1 is greater than 0.5, so we have a 50% to get true and 50% to get false.
items: any[];
items.forEach( (item) => {
item.randomBooleanProperty = Math.random() >= 0.5; //true of false
});
Upvotes: 5