-1

How could I acess and console.log() the value from the key that I'm given here:

Object { USD_GBP: 0.726718 }

I wish to access the 0.726718 from the key USD_GBP.

I'm trying to do this in JavaScript.

HJP
  • 47
  • 4

1 Answers1

0

Here is an example showing few ways to read the value of a key within an object:

    const obj = {USD_GBP: 0.726718};
    console.log(obj.USD_GBP); 
    console.log(obj['USD_GBP']);
    // good if you can hardcode the key.
    // Maybe your key is in a variable or constant.
    // In that case, you can do something like:
    const runtimeKnownKey ='USD_GBP'; 
    console.log(obj[runtimeKnownKey]);
Josh
  • 141
  • 2
  • 6