I’ve got a Backbone Collection. How can I slice the collection, or at least truncate the list to a certain length?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
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:
Here is a list of all the underscore methods you can use directly on your collection.