search

Home  >  Q&A  >  body text

javascript - How to determine the length of empty array elements in JS

Object.prototype.toString.call(val) == '[object Array]' ? val.some(e => e != undefined && e != null && e != '') : false;

val is the array after the splice(0, 1) operation. I want val.some to return in the situation shown below. false

淡淡烟草味淡淡烟草味2828 days ago562

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-19 10:14:26

    Array.prototype.some will skip elements with value undefined

    If you need to consider undefined, you need to write a for loop to traverse it.

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-05-19 10:14:26

    If indeed some, the callback method will not be executed.

    reply
    0
  • Cancelreply