Assuming originalCollection is your existing collection
var newCollection = new Backbone.Collection(); for (var i = 0, l = originalCollection.length; i < l; i++) { if (i % 3 === 0) { newCollection.add(originalCollection.models[i]); } }
This code works by cycling through each existing model and adds only a new collection if the index is a multiple of 3.
You can do this a little better by using the underline method each , opened by Underscore.js in Backbone Collections:
var newCollection = new Backbone.Collection(); originalCollection.each(function (model, index) { if (index % 3 === 0) { newCollection.add(model); } });
Converting the above to CoffeeScript results in:
newCollection = new Backbone.Collection() originalCollection.each (model, index) -> newCollection.add model if index % 3 is 0
source share