Retrieving Data From Collections

Sometimes you need to retrieve specific values from each Model in a Collection, at other times you may want to check if a Collection meets certain criteria and perform an action accordingly. The next three methods don't return any specific data, rather they return true or false depending on if the collection passes a test.

Methods Returning a Boolean

These methods return a boolean:

  • every or all: returns true if all the models pass a test
  • some or any: returns true if any of the models pass a test
  • include or contains: returns true if the collection contains a passed in model

Again to illustrate these methods, let's run some tests on our sample data. In the following code we're going to check if our collection ...

Get Developing a Backbone.js Edge now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.