I've got a Backbone Collection. How can I slice the collection, or at least truncate the list to a certain length?
Assuming that you have your collection defined and initialized and that you want to mutate the collection (change it in place) you have to do:
collection.reset(collection.first(n));
of you can use .last(n)
to get last N elements.
If you just wanted to get the first n elements without modyfying the collection just do:
var models = collection.first(n);
Here is a list of all the underscore methods you can use directly on your collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With