O'Reilly logo

KnockoutJS Web Development by John Farrar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Utility functions

There are a number of functions in ko.utils. Let's start by looking at the special array methods in standard Knockout.

ko.utils.arrayFilter()

The ko.utils.arrayFilter function allows us to filter items in an array. We are going to run these as straight code examples. We will create a sample JSON file and load it via AJAX to keep the focus on learning the methods and not waste time creating an example code set. We will create a page called utility.html for these pieces of code and run the filtering code from there. Our markup for this example is here:

<h3>arrayFilter() : staff under 35</h3>
<ul data-bind="foreach: youngStaff">
  <li><span data-bind="text: age() + ' ' + firstName()"></span></li>
</ul>

Our script code is as follows. We ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required