fcf.count() function
Package: fcf-framework-core
File: fcf-framework-core:fcf.js
Available from version: 2.0.2
Determines the number of elements in an object or a string. The function works both with simple objects and with arrays,
Arguments
- Source object
- If a function is given, then a_cb is called sequentially for each element of the array to determine the number of elements, and if the function returns true , then the element is counted in the total subset.
Function signature:
Result
- Number of counted elements in an object or a string
If the passed argument is not an object or a string, returns
Example: Function application
console.log(`[1,2,3] :`, fcf.count([1,2,3]));
console.log(`{"k1": "v1"} :`, fcf.count({"k1": "v1"}));
{
let map = new Map();
map.set("k1", "v1");
console.log(`Map({"k1": "v1"}) :`, fcf.count(map));
}
{
let result = fcf.count([1,2,3,4],
(a_key,a_value) => { return a_value % 2 == 0; });
console.log(`[1,2,3,4] if value%2 == 0 :`, result);
}
Output:
[1,2,3] : 3
{"k1": "v1"} : 1
Map({"k1": "v1"}) : 1
[1,2,3,4] if value%2 == 0 : 2