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);
where
  • the begin shows the starting point of array.
  • the end shows the ending point of the array.
Example :
<script> 
  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);
</script>
Output :


Next Topic :