If statement to move past [ ] in a https get response

Viewed 32

I am trying to write a trading algo and I am moving through tickers for quote. When I come to a certain tickers that responds with []. My list stops iterating. I have tried several different if statements to move past any ticker that returns [] but it is still stopping on these tickers, any ideas?

if(msg == undefined || msg == []){
         count++
         nextTicker()
         getVolume()
        // console.log("Next Ticker: ", nextTicker1, "Next Quote: ", nextQuote1)
        // console.log(msg)
       }else if(msg.price == null || msg.price == undefined){
         count++
         nextTicker()
         getVolume()
       }else if(msg.price != null){
         count++
         nextTicker()
         getVolume()
         console.log("Next Ticker: ", nextTicker1, "Next Quote: ", nextQuote1)
         console.log(msg)
       }

example of ticker response via a browser

example of a good ticker response via algo

2 Answers

You can't compres two arrays, since JS objects are stored in memory as reference, this comparisson returns always false:

let arr1 = [];
let arr2 = [];

console.log(arr1 == arr2);  // Always false in JS

To check an empty array you can get his length, try this:

let arr = [];
console.log(arr.length == 0)

In your code you have to do this:

if(msg.length == 0){
  // your code
}

Related