I have the following array of objects
position = [
{exchange: 'KRAKEN', USD: 1800, EUR: 800, GBP: 800, BTC: 800},
{exchange: 'BTCE', USD: 800, EUR: 800, GBP: 800, BTC: 800},
{exchange: 'BITSTAMP', USD: 600, EUR: 800, GBP: 800, BTC: 800},
{exchange: 'MYWALLET', USD: 1300, EUR: 800, GBP: 800, BTC: 800}
]
I also have 2 variables: myExchange and myCurr
I'm attempting to extract the relevant currency value from the array. i.e. if myExchange = 'KRAKEN' and myCurr = USD,then I need to fetch the result as = 1800
I'm using the following code in coffeescript (and underscore ._ as library) but it is returning as 'undefined'
objBuy = _.find(position, (objBuy) ->
objBuy.exchange is buyExchange
)
objBuyCurr = _.find(objBuy, (objBuyCurr) ->
objBuy._key is buyCurr
)
Eventually what I'm aiming for is to pass the object property/keys as variables dynamically. i.e.: value = position.myExchange.myCurr (and NOT position.KRAKEN.USD)