CodesJava

Easy learning with example program codes

Backbone.JS Slice() collection


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:

<!DOCTYPE html>  
<html>
<head>  
<title>Example</title>  
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" 
type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" 
type="text/javascript"></script>  
</head>  
<body>  
<script type="text/javascript">  
var rhyme = Backbone.Model.extend();  
var X =['Jim', 'Kim', 'Sim', 'Tim', 'Vim'];  
var Y = new Backbone.Collection(X,{  
model:rhyme  
});  
var Z = X.slice(2,5);   
document.write("Number of rhyming names:", +Z.length);  
document.write("<br>");  
document.write(JSON.stringify(Z));    
</script>  
</body>  
</html>

Output:

Number of rhyming names:3
["Sim","Tim","Vim"]

Explanation:
In the above example, the Slice() method begins the element extraction at index 2 and ends the extraction of elements at index 5.

Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki