Skip to main content

.count()

A function that counts the number of elements in a given array that satisfy the condition of a specified function.

Syntax

#fs.scripts.lib().count(array, func);

Parameters

array

The array of elements to be evaluated.

func

The function to be executed. This function should return a boolean.

Return

Returns a number.

Example

function(context, args) {
const l = #fs.scripts.lib();
const my_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

function is_even(index, value) {
return value % 2 === 0;
};

return l.count(my_array, is_even);
}