Getting a count of list items in a list via ECMAScript
<p>I have a SharePoint 2010 web site with a master page that has a counter on it. I'm trying to update that counter using the ECMAScript. The code I have falls nicely into the success method - but I cannot find the right call to get a count. I have tried length, length(), count &amp; count(). Does anybody have any suggestions?  I have the code working, but only by enumerating through the results of the list and incrementing a count.</p>

<p>This is what I have so far, as an example:-</p>

<pre><code>&lt;script type="text/javascript"&gt;
    var clientContext = null;
    var web = null;
    ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
    function Initialize()
    {
        clientContext = new SP.ClientContext.get_current();
        web = clientContext.get_web();
        var list = web.get_lists().getByTitle("Absences");
        var camlQuery = new SP.CamlQuery();
        var q = "&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='StatusID' /&gt;&lt;Value Type='Integer'&gt;1&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;";
        camlQuery.set_viewXml(q);
        this.listItems = list.getItems(camlQuery);
        clientContext.load(listItems, 'Include(Id)');
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess), 
        Function.createDelegate(this, this.onQueryFailed));
    }
    function onListItemsLoadSuccess(sender, args) {
        var count = 0;
        var listEnumerator = this.listItems.getEnumerator();
        //iterate though all of the items
        while (listEnumerator.moveNext()) {
            count = count + 1;
        }

        $('#spnNumberOfAbsences').text(count);
    }

    function onQueryFailed(sender, args) {
        alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
    }
&lt;/script&gt;
</code></pre>
