Use of Array.slice() method in Javascript.

Rajesh_Kumar
Posted by Rajesh_Kumar under JavaScript category on | Points: 40 | Views : 559
Array.slice() Method extracts part of array and returns a new array.Slice() Method is similar to Substring function of C# string.

function array_slice_method() 
{
var array_names = new Array(6);
array_names[0] = "Rajesh";
array_names[1] = "Kumar";
array_names[2] = "Sathua";
array_names[3] = "Vipin";
array_names[4] = "Seema";
array_names[5] = "Vinita";

array_items = array_names.slice(0, 1);
document.writeln(array_items);

array_items = array_names.slice(1, 2);
document.writeln(array_items);

array_items = array_names.slice(1, 3);
document.writeln(array_items);

array_items = array_names.slice(2, 4);
document.writeln(array_items);

array_items = array_names.slice(5);
document.writeln(array_items);
}


Output would be:
Rajesh
Kumar
Kumar,Sathua
Sathua,Vipin
Vinita

Comments or Responses

Login to post response