Method search documentation

Retrieves the index of the array's first element corresponding to the given filter.

Example

```javascript let ar = [ {name: "Raiders of the lost ark", director: "Steven Spielberg", year: 1981, id: 589}, {name: "Goonies", director: "Richard Donner", year: 1985, id: 689}, {name: "Star wars", director: "George Lucas", year: 1977, id: 256}, {name: "Jaws", director: "Steven Spielberg", year: 1975, id: 423} ]; bbn.fn.search(ar, "id", 256); // 2 bbn.fn.search(ar, {director: "Steven Spielberg"}); // 0 bbn.fn.search(ar, {year: 1975, director: "Steven Spielberg"}); // 3 bbn.fn.search(ar, {director: "Steven Spielberg"}, 1); // 3 // Complex filters bbn.fn.search(ar, { logic: "AND", conditions: [ { field: "director", operator: "eq", value: "Steven Spielberg" }, { logic: "OR", conditions: [ { field: "year", operator: "eq", value: 1974 }, { field: "year", operator: "eq", value: 1975 } ] } ] }); // 3 Simple array bbn.fn.search(['a', 'b', 'c'], null, 'b'); // 1 ```

Retrieves the index of the array's first element corresponding to the given filter. - Returns -1 if the element is not found. If the second parameter is an object or function for filtering as defined in bbn.fn.filter, the remaining parameters will be shifted to the left, i.e. val becomes operator, and operator startFrom. And if operator is a number, its value will be given to startFrom and operator will be undefined. The filter object can be complex with different operators (as seen in bbn.fn.compare) and logics (AND/OR), and infinitely nested, of this form: ```javascript { logic: "AND", conditions: [ { field: "prop1", operator: "eq", value: "value1" }, { logic: "OR", conditions: [ { field: "prop2", operator: "eq", value: 1 }. { field: "prop2", operator: "eq", value: 2 } ] } ] } ``` This way of managing the arguments is used in all the filtering functions. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way

This website uses cookies to ensure you get the best experience on our website.