Javascript Array filter not filtering

前端 未结 2 861
有刺的猬
有刺的猬 2021-01-26 05:53

I cannot get Javascript to filter a dynamically created array, although it filters a static array fine. Code block #1 works (static array), code block #2 doesn\'t (dynamically

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 06:27

    _eventsArray in your second example is an HTMLCollection not a JS Array. You can convert it like the following:

    function getRowCalendarEvents (_eventsArray,_unitValue) {
        var arr = [].slice.call(_eventsArray);
    
        return arr.filter(function(_calendarEvent) {
        return _calendarEvent.unit == _unitValue;
      }); 
    }
    

提交回复
热议问题