Backbone.JS Comparator()

The Backbone.JS Comparator() collection method is used to sort the items in the collection. Syntax: Collection.Comparator Example: Example Output: Sorted based on id: [{“id”:2,”name”:”Jim”},{“id”:10,”name”:”Tom”},{“id”:33,”name”:”Kim”}] Explanation: In the above example, the Comparator() method maintains the collection in sorted order based on the value of the ‘id’.

Backbone.JS Length()

The Backbone.JS Length() collection method counts the number of models in the collection. Syntax: Collection.Length Example: Example Output: Number of added numbers : 2 Explanation: In the above example, the Length() method counts the number of added models to the collection.

Backbone.JS Slice()

The Backbone.JS Slice() collection method displays the shallow copy of the elements from the collection model. Syntax: Collection.Slice ( begin, end ) Parameters: begin: This parameter is used to specify the beginning of the element. end: This parameter is used to specify the end of the element. Example: Example Output: Number of rhyming names:3 [“Sim”,”Tim”,”Vim”] … Read more

Backbone.JS Shift()

The Backbone.JS Shift() collection method removes the first item from the collection. Syntax: Collection.Shift ( options ) Parameters: options: This parameter is used to specify the model types. Example: Example Output: Original array:[{“id”:100,”name”:”Jim”,”age”:11},{“id”:200,”name”:”Tim”,”age”:9}] After Shift:[{“id”:200,”name”:”Tim”,”age”:9}] Explanation: In the above example, the Shift() method removes the model Student1 from the collection.

Backbone.JS Unshift()

The Backbone.JS Unshift() collection method adds a specified model at the beginning of a collection. Syntax: Collection.Unshift ( models, options ) Parameters: models: This parameter is used to specify the models to be added to the beginning of the collection. options: This parameter is used to specify the model types. Example: Example Output: [{“id”:200,”name”:”Tim”,”age”:9},{“id”:100,”name”:”Jim”,”age”:11}] Explanation: … Read more

Backbone.JS Pop()

The Backbone.JS Pop() collection method is used to remove the models from the collection. Syntax: Backbone.Collection.Pop ( models, options ) Parameters: models: This parameter is used to specify the models to be removed from the collection. options: This parameter is used to specify the model types. Example: Example Output: Number of numbers added: 3 Number … Read more

Backbone.JS Push()

The Backbone.JS Push() collection method push the models to a collection, which simply means that it adds a model to the end of a collection. Syntax: Backbone.Collection.Push ( models, options ) Parameters: models: This parameter is used to specify the models to be Pushed to the collection. options: This parameter is used to specify the … Read more

Backbone.JS At()

The Backbone.JS At() collection method retrieves a model from a collection by using a specified index. Syntax: index() Parameters: index: This parameter is used to specify the index position for the retrieval of the model from a collection. Example: Example Output: Old Students List: [{“id”:1,”name”:”Tom”},{“id”:2,”name”:”Jerry”}] New Students List: [{“id”:1,”name”:”Tom”},{“id”:2,”name”:”Jerry”},{“id”:3,”name”:”Bruno”}] Explanation: In the above example, the … Read more

Backbone.JS Get()

The Backbone.JS Get() collection method retrieves a model from a collection by using id or Cid. Syntax: Backbone.Collection.Get (id ) Parameters: id: This parameter is used to specify the id of the model to be retrieved from the collection. Example: Example Output: Hello World! Explanation: In the above example, the Y object gets the X … Read more

Backbone.JS Set()

The Backbone.JS Set() collection method is used to update a collection with a set of items in a model. Syntax: Backbone.Collection.Set ( models, options ) Parameters: models: This parameter is used to specify the models to be set in the collection. options: This parameter is used to specify the parameters like id, name, etc. Example: … Read more