Backbone.JS toJson() collection

The Backbone.JS toJson() collection method is used to get a copy of the attributes of a model using JSON format in the collection.

Syntax:

Collection.toJson (options)      

Parameters:
options: This parameter is used to specify the options as collection instance.

Example:

 

  
Example  
  
  
  
  
  
  
  


  


Output: 
Collection:[{"name":"Jim"},{"name":"Minii"},{"name":"Tiny"}]

Explanation:
In the above example, the model ‘X’ includes the default values and is extended using the Backbone.Model class, ‘XCollection’ is a collection instance and The 'Z.toJson' defines the array of toJson inside the collection.