<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.count.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.count</api:function-name><api:suggest>fn.count</api:suggest><api:suggest>fn</api:suggest><api:suggest>count</api:suggest><api:function-link mode="xquery" fullname="fn:count">/apidoc/8.0/fn:count.xml</api:function-link><api:function mode="javascript" name="count" type="builtin" lib="fn" category="SequenceBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.count"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">Returns the number of items in the value of $arg.
</p><p xmlns="http://www.w3.org/1999/xhtml">
Returns 0 if $arg is the empty sequence.
</p>
</api:summary><api:params><api:param name="arg" type="item()*"><api:param-description>
  The sequence of items to count.  
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">If you pass in a single value, 
  it is treated as a ValueIterator 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 
  <a href="./xdmp.arrayValues">xdmp.arrayValues</a> on the array. </span>
  </api:param-description><api:param-name>arg</api:param-name><api:param-type>ValueIterator</api:param-type></api:param><api:param name="maximum" type="xs:double?" optional="true"><api:param-description>
  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 <code xmlns="http://www.w3.org/1999/xhtml">fn:count</code> function.
  </api:param-description><api:param-name>maximum</api:param-name><api:param-type>Number?</api:param-type></api:param></api:params><api:return>Number</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var seq1 = xdmp.arrayValues(["item1", "item2"]);
var seq3 = null ;
fn.count(seq1);
=&gt; 2

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

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

var seq = xdmp.arrayValues([98.5, 98.3, 98.9]);
var seq2 = new Array();
for (var x in seq) {
  if (x &gt; 100) {
    seq2.push(x);
  }
};
fn.count(xdmp.arrayValues(seq2)); 
=&gt; 0
</pre>
</api:example></api:function></api:function-page>