jQuery.grep()


jQuery.grep( array, function [, invert ] )Возвращает: Array

Описание: Ищет в заданном массиве элементы, удовлетворяющие условиям фильтрующей функции. Возвращает массив с найденными элементами (в исходный массив изменения не вносятся).

  • Добавлен в версии: 1.0jQuery.grep( array, function [, invert ] )

    • array
      The array-like object to search through.
    • function
      Тип: Function( Object elementOfArray, Integer indexInArray ) => Boolean
      The function to process each item against. The first argument to the function is the item, and the second argument is the index. The function should return a Boolean value. this will be the global window object.
    • invert
      Тип: Boolean
      If "invert" is false, or not provided, then the function returns an array consisting of all elements for which "callback" returns true. If "invert" is true, then the function returns an array consisting of all elements for which "callback" returns false.

The $.grep() method removes items from an array as necessary so that all remaining items pass a provided test. The test is a function that is passed an array item and the index of the item within the array. Only if the test returns true will the item be in the result array.

The filter function will be passed two arguments: the current array item and its index. The filter function must return 'true' to include the item in the result array.

Примеры использования