Search code examples
javascriptobjectkey

How give key object through condition 'if'?


I used websocket to get a channel. Using the condition for the 'event' you need to output to the console the id and the name of the pair.

let ChanIds = {};
w.on('message',(msg) => {
  console.log(msg);
        if (msg.event) {
        }
});
{"event":"subscribed","channel":"ticker","chanId":4,"symbol":"tBTCUSD","pair":"BTCUSD"}"
 let ChanIds = { 4 : tBTCUSD };
  

Need to give a key to an object


Solution

  • let chanIds[someObject.chanId] = someObject.symbol