response.data !== undefined && response.data.length > 0 

The condition should check:

  1. Is there an "data" array?
  2. Does it have meaning?

    1 answer 1

    Checking for undefined is not enough. So there may not be an array, but any value, for example, null. You need to check that this is really an array and then check the size.

     var data = response.data; if(Object.prototype.toString.call(data) == "[object Array]" && data.length > 0) { // data - это массив и в нем есть элементы } 
    • one
      and you can just remove one sign = - Grundy
    • @Grundy yes. but if the object does not have the length property, but there will be an error. - Mikhail Vaysman
    • Why did it happen?. undefined > 0 === false - Grundy
    • Well, if the object does not have length, then checking length is an error in the logic of the program. - Mikhail Vaysman
    • one
      And why can't we check that it is an array like this Array.isArray(...) , instead of the prototype? - Yuri