Then secondly, the filter() function accepts another argument that is optional but takes the “this” value of the callback function else, it will take “undefined” as the value. This callback function further invokes the value of each element, the index of each element, and the array object that is being selected for traversing through the array where all these are optional except the value of each element as it is used for filtering the certain elements in the array. This function takes a callback argument which is invoked for each element in the array, and then it creates the new array that has the elements returned by the callback function if true, else it returns an empty array. In typescript, the filter() method is an in-built array function to filter the given set of elements in an array to get a subset of elements of the given array, and the filter() method works as follows:įirstly, this method is applied to the array that is defined or declared to which the set of elements needs to be extracted from the given array. How does the filter() method work in Typescript with examples? Sometimes in the above syntax, the parameter callback has 3 more parameters such as current value, which holds the present element value of the given array, the second parameter is an index which indicates the index of the element in the given array, which is optional and the third parameter is an array which is used for calling this filter function. This array method returns the new array, which consists of the part of array elements that are filtered using this method on the given array, and the elements in the sub-array will be returned only if it passes the test given in the callback parameter else, it will return an empty array if it is false. ThisObject: this parameter is used when the above parameter is executed, which is an object. In the above syntax, the filter() method is applied on the array to which we need to extract the given array elements, and this subset of the array is returned, which takes two parameters.Ĭallback: this parameter consists of a function that is used for testing each element in the array. IdFilter - A filter which matches any contact whose local id is contained in a particular list of contact local ids.Syntax: var arr1 = array.filter(callback) UnionFilter - A filter which matches any contact that is matched by any of the filters it includes. IntersectionFilter - A filter which matches all contacts that are matched by all filters it includes. RelationshipFilter - A filter which matches contacts which participate in a particular type of relationship, or relationship with a specified contact. ActionFilter - A filter which matches contacts for which a particular action is available, or which contain a detail with a particular value for which a particular action is available. ChangeLogFilter - A filter which matches contacts whose timestamps have been updated since some particular date and time. DetailRangeFilter - A filter which matches contacts containing one or more details of a particular definition whose values are within a particular range. DetailFilter - A filter which matches contacts containing one or more details of a particular definition with a particular value. InvalidFilter - An invalid filter which matches nothing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |