Alex Rivera | Logout

Count of "Defined" Array Elements

Asked 2012-03-28T06:04:33.540
35

Given following array:

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

I'd like to get the count of elements which are defined (i.e.: those which are not undefined). Other than looping through the array, is there a good way to do this?

Edit
Report

1 Answer

0

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

EDIT :

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

answered 2012-03-28T06:08:29.133

Your Answer