0

My goal is based on wether values_Series or not If console.log(values_Series) is an empty array, my goad is to use table1 as data set and draw a scatter in the same color. The program will go to:

if (values_Series == []){
        serie.push({
            
            type:'scatter',
            data: table1,
            symbolSize: 20,
            color : '#c110d5'
            
        })
    }

otherwise, if values_Series is not an empty array, my goal aims to use table2 as data set, use for loop to draw a different scatter.

if (values_Series != []){
        for (let i = 0; i < n; i++){
            serie.push({
                name: values_series[i],
                type:'scatter',
                data: table2[i],
                symbolSize: symbolsize[i]
            })
        }
    }   

However, the code always goes to the second part, even values_Series is empty!

  if (values_Series == []){
        serie.push({
            
            type:'scatter',
            data: table3,
            symbolSize: 20,
            color : '#c110d5'
            
        })
    }
    if (values_Series != []){
        for (let i = 0; i < n; i++){
            serie.push({
                name: values_series[i],
                type:'scatter',
                data: data[i],
                symbolSize: symbolsize[i]
            })
        }
    }   
  • 2
    Run `[] == []` in a JS console. You may mean `anArray.length === 0`. – Dave Newton Jul 18 '20 at 03:18
  • In javascript, as a rule of thumb, only use == on primitives like strings, numbers, true/false, undefined, etc. Never use it on objects (unless you're wanting to check if two objects have the same identity). – Scotty Jamison Jul 18 '20 at 03:24

0 Answers0