如果在 https 中移过 [ ] 的语句得到响应

问题描述

我正在尝试编写一个交易算法,我正在浏览报价单。当我遇到以 [] 响应的特定代码时。我的列表停止迭代。我尝试了几种不同的 if 语句来移动返回 [] 的任何股票代码,但它仍然在这些股票代码上停止,有什么想法吗?

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: ",nextQuote1)
         console.log(msg)
       }

example of ticker response via a browser

example of a good ticker response via algo

解决方法

你不能压缩两个数组,因为JS对象作为引用存储在内存中,这个比较总是返回false:

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

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

要检查一个空数组,你可以得到他的长度,试试这个:

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

在您的代码中,您必须这样做:

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

,

此链接中的响应不是 [],而是 [ ]

example of ticker response via a browser