Grep vs Filter in jQuery?

前端 未结 5 456
天命终不由人
天命终不由人 2020-12-13 11:36

I was wondering about the differences between Grep and Filter :

Filter :

Reduce the set of matched elements to those that match the selector

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 12:37

    The difference in its usage:

    Filter:

    $(selector).filter(selector/function)
    

    Grep:

    $.grep(array,function,invert)
    

    So in your case I would rather use grep() because using array this way is unnecessary: $(arr).

    I also suppose that grep function is faster, because it only accepts arrays.

提交回复
热议问题