Articles → JAVASCRIPT → Array Slice Function In Javascript

Array Slice Function In Javascript






Purpose





Syntax


arr_object.slice(); // This will copy the whole array

arr_object.slice(start_index); // This will copy an array from start_index to end of the array

arr_object.slice(start_index, end_index); // This will copy an array from start_index to end_index of the array



Example


<script>
  var arr = ["e1", "e2", "e3", "e4"];
         
  console.log(arr.slice());
  console.log(arr.slice(1));
  console.log(arr.slice(2, 3));
</script>

Try It


Output


Picture showing the output of Array slice function in JavaScript



Posted By  -  Karan Gupta
 
Posted On  -  Saturday, September 4, 2021

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250