Count of “Defined” Array Elements

后端 未结 7 1594
无人及你
无人及你 2020-12-03 04:30

Given following array:

var arr = [undefined, undefined, 2, 5, undefined, undefined];

I\'d like to get the count of elements which are

7条回答
  •  被撕碎了的回忆
    2020-12-03 05:20

    Unfortunately, No. You will you have to go through a loop and count them.

    EDIT :

    var arrLength = arr.filter(Number);
    alert(arrLength);
    

提交回复
热议问题