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

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

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

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

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

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.

Comments

The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.