Loading TOC...

fn.count

fn.count(
   $arg as Sequence,
   [$maximum as Number?]
) as Number

Summary

Returns the number of items in the value of $arg.

Returns 0 if $arg is the empty sequence.

Parameters
$arg The sequence of items to count. If you pass in a single value, it is treated as a Sequence with that single item; therefore, if you pass in an array, the array is treated as a single value (not as one value for each item in the array). If you mean to pass in the values of each item in the array, then you can call xdmp.arrayValues on the array.
$maximum The maximum value of the count to return. MarkLogic Server will stop count when the $maximum value is reached and return the $maximum value. This is an extension to the W3C standard fn:count function.

Example

var seq1 = xdmp.arrayValues(["item1", "item2"]);
var seq3 = null ;
fn.count(seq1);
=> 2

var seq1 = xdmp.arrayValues(["item1", "item2"]);
var seq3 = null ;
fn.count(seq3);
=> 0

var seq2 = xdmp.arrayValues([98.5, 98.3, 98.9]);
fn.count(seq2);
=> 3

var seq = xdmp.arrayValues([98.5, 98.3, 98.9]);
var seq2 = new Array();
for (var x in seq) {
  if (x > 100) {
    seq2.push(x);
  }
};
fn.count(xdmp.arrayValues(seq2)); 
=> 0

Comments

    Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy