search

Home  >  Q&A  >  body text

javascript - Why does this happen under IE? "Cannot get property 'length' of undefined or null reference"? Please give me some advice.

伊谢尔伦伊谢尔伦2710 days ago1474

reply all(1)I'll reply

  • 为情所困

    为情所困2017-06-27 09:21:24

    Because the object may be an undefined or null value, and the undefined or null value does not have a length attribute

    You can write it like this

    if (listVal && listVal.length == 0) {
      // do something...
    }

    reply
    0
  • Cancelreply