find()
finds the item that corresponds to the specified rule
find(rule: object | (item: object, index?: number, array?: object[]) => any): object;
Parameters:
rule: object | function
- the search criteria:- if set as an object, the parameter contains the following attributes:
by: string | function
- the search criterion (either the key of the item attribute or a search function)match: string
- the value of the item attribute
- if set as a function, the search will be applied by the rule specified in the function. The function takes three parameters:
item
- (required) the object of an itemindex
- (optional) the index of an itemarray
- (optional) an array with items
- if set as an object, the parameter contains the following attributes:
Returns:
An object of the matching item.
Example
//searching for an item by the function
const item = component.data.find(function(item){
if(item.text==="Manager"||item.text==="Marketer"){return true}
});
//searching for an item by the attribute key
const item = component.data.find({by:"text",match:"Manager"});
Related sample: Data. Find