For example, if I define code like this
var price;
$.getJSON('https://api.coindesk.com/v1/bpi/historical/close.json?start=2013-09-01&end=2013-09-05', function( data ) {
  price = data.bpi;
});
then I can get price from console;
However, if I define code like this
var price;
$.getJSON('https://api.coindesk.com/v1/bpi/historical/close.json?start=2013-09-01&end=2013-09-05', function( data ) {
  price = data.bpi;
});
console.log(price);
the price can still be accessed from console, but console.log returns undefine.
My question is that how can I get the price returned from data.api, so I can latter use the data to do some further calculation, such as
var x = Object.keys(price);
var y = Object.values(price);
// some plot using x, y, and some calculations
 
     
    