1

so what i'm trying to do is get live prices between crypto coins it was going smoothly until some id came with dash and the problem appear

enter image description here

here is the code

var btcbnb, ethbnb, usdtbnb, usdcbnb, ltcbnb;
  var btcln, ethcln, usdtcln, usdccln, ltcln, bnbln ,bch;
  var liveprice11 = {
    "async": true,
    "scroosDomain": true,
    "url": "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin%2Cethereum%2Cusd%2Clitecoin%2Cbinancecoin%2Cbinance-peg-bitcoin-cash&vs_currencies=bnb%2Clink%2Cusd",
  
    "method": "GET",
    "headers": {}
  }
  
  $.ajax(liveprice11).done(function (response){
    btcbnb = response.bitcoin.bnb;
    ethbnb = response.ethereum.bnb;
    usdtbnb = response.ethereum.bnb;
    usdcbnb = response.usd.bnb;
    ltcbnb = response.usd.bnb;
    // link
    btcln = response.bitcoin.link;
    ethcln = response.ethereum.link;
    usdtcln = response.usd.link;
    usdccln = response.usd.link;
    ltcln = response.litecoin.link;
    bnbln = response.binancecoin.link;
    bch = response.binance-peg-bitcoin-cash.usd;
    console.log(bch);
  });

this is the line that has the problem

 bch = response.binance-peg-bitcoin-cash.usd;

really hope someone can help ,thanks

1 Answer 1

1

As you found, JS doesn't let you access object members by name that have a dash like that.

A simple workaround would be

bch = response['binance-peg-bitcoin-cash'].usd;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.