0

if I have an object:

let Cars = {Banna:'Yellow'},{Apple:'Red'}

Can I have a viable be a key that changes based on user input?

function button(userinput){
let key = userinput
}
let fruit = Cars.key

The Object I have in my code is much longer than this example.

BlackCode
  • 5
  • 4
  • `let Cars = {Banna:'Yellow'},{Apple:'Red'}` ... try `console.log(Cars)` ... what do you see? – Bravo Nov 16 '20 at 00:59
  • as for your function - `key` is only accessible inside `button` function, and `let fruit = Cars.key` should be `let fruit = Cars[key]` ... but that's not evaluated more than once, and the value of `key` inside bButton` will not be relevant for the aforementioned reason – Bravo Nov 16 '20 at 01:00

0 Answers0