dimanche 9 août 2020

Why does an empty array pass the if(array !== []) check

Hi I've been debugging a javascript issue where an empty array default value set in state, passes a conditional check which checks if it is empty.

I must be overlooking something. Here is what I have:

state = {
  array: []
};

if(array !== []){
  //do something
}

I also have a check for if it is empty - although I need to extend it so that this [] array doesn't return true.

I have also tried array.length > 0 in lieu of checking against [].

Any ideas please?

Thanks

Aucun commentaire:

Enregistrer un commentaire