0

I have an object containing a checklist below that I would like to get values from.

colors = {
    green: true, 
    blue: true, 
    red: true, 
    orange: false
}

How will I get the value (e.g. true/false) just by using the keys?

Pseudocode:

const isUsed = (color) => {
    return if true or false given the color
}

Expectations:

console.log(isUsed("green"));
//logs true
G Josh
  • 271
  • 1
  • 5
  • 15

2 Answers2

0

const colors = {
    green: true, 
    blue: true, 
    red: true, 
    orange: false
}


const isUsed = (color) => {
    return colors[color]
}

console.log(isUsed('green'))
console.log(isUsed('orange'))
cmgchess
  • 7,996
  • 37
  • 44
  • 62
0
const isUsed = color => colors[color]

This will return true or false if the value color exists in colors, or it will return undefined if it doesn't

Itay S
  • 73
  • 7