Filter - method of the PmArray object
Description:
Allows to filter 1-dimensional array.
Syntax:
Array Filter(Function onFilter)
Parameters:
onFilter | (Function) The onFilter parameter contains the function, that allows filtering of the 1-dimensional array.
The onFilter function user-detects whether the array item belongs/does not belong to the resulting array. This function is called sequentially for each array item during filtering and must be in the following form:
function onFilter(vItem, iItem) { return vItem > 10 ? true : false; }
where the vItem parameter contains the value of the array item and the iItem parameter contains the index of the item in the array.
The function returns:
true - if the item meets the filtration condition
false - if the item does not meet the filtration condition |
---|
Return value:
1-dimensional array - copy of the input array containing only items that meet the filtering condition.
Example:
JavaScriptSelect and copy to clipboard
function onFilter(vItem, iItem)
{
return vItem > 10 ? true : false;
}
var arr1 = Pm.Array1(2, 11, 5, 23, 45, 8, 10, 19);
var arr2 = arr1.Filter(onFilter);
// The array will be filtered as follows: 11, 23, 45, 19