Javascript - Count array objects that have a value

后端 未结 8 600
情话喂你
情话喂你 2021-01-19 01:52

I\'m getting an array returned to me and I need to count the rows that have a value in them

I\'ve tried to call arr.length but that gives me the total length of the

8条回答
  •  执笔经年
    2021-01-19 02:43

    You can try this:

    var count = 0;
    for (var x of arr) {
      if (x.id != '') {
        count++;
      }
    }
    

    Basically what I do is that loop through all the object and if it's not an empty string, then count it.

提交回复
热议问题