Jump to content


Photo
Question

how do i push a data to an array ?



  • Please log in to reply
2 replies to this topic

#1 xLeeJYx

xLeeJYx

    Advanced Member

  • Member
  • PipPipPip
  • 70 posts

Posted 14 July 2017 - 08:32 AM

With this code below i got [ ] in console. Not sure what i done wrong

function priceCheckCard(item) {

    var cardPrices = [];

    market.getItemPrice(item.appid, item.market_hash_name, (err, data) => {
        if (err) {
            console.log(err.message)
        } else {
            cardPrices.push(data.median_price)
        }
    })
    return cardPrices
}

 



#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,361 posts

Posted 14 July 2017 - 03:30 PM

You're pushing the data correctly, you just seem to not understand async. Calling market.getItemPrice is essentially requesting that it retrieve the item price and then let you know when it's finished. You then return immediately, without waiting for the callback.



#3 xLeeJYx

xLeeJYx

    Advanced Member

  • Member
  • PipPipPip
  • 70 posts

Posted 14 July 2017 - 09:50 PM

You're pushing the data correctly, you just seem to not understand async. Calling market.getItemPrice is essentially requesting that it retrieve the item price and then let you know when it's finished. You then return immediately, without waiting for the callback.

i really cant understand a single thing about async ._. i looked through the google and youtube but still cant understand







Also tagged with one or more of these keywords: Question

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users