JavaScript Array Method : slice()

The slice() method is used to slice-out a section of array and and create a new array from it. Also note that since slice() method creates a new array, but it does not remove any elements from the source array. The basic syntax of slice() is as follows :
  array.slice(begin, end);
  • the begin shows the starting point of array.
  • the end shows the ending point of the array.
Example :
  var vagitables = ["Potato", "Onion", "Tomato", "Apple", "Mango", "Banana", "brinjal"];
  document.write("Vagitables are : " + vagitables + "<br/>");
  var fruits = vagitables.slice(3, 6)
  document.write("fruits : " + fruits);
Output :

Next Topic :