I have this simple code that works. However it feels cheesy and like I am doing something stupid. So is this how I would handle this if I wanted to be in one line?
let lifeColors = [
{ lives: 1, color: 'lime' },
{ lives: 2, color: 'orange' },
{ lives: 3, color: 'salmon' },
]
let lives = 20;
let color = (lifeColors.find(x => x.lives === lives) || {color: 'white'}).color;
console.log(color)
My inspiration was from this post