You can use the
let array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let subArray = array.slice(3, 7); console.log(subArray); // This will output [4, 5, 6, 7]
In this example, the
slice() method takes two arguments: the start index and the end index. The start index is inclusive, and the end index is exclusive. So
array.slice(3, 7) returns a new array starting from the 4th element (index 3) up to (but not including) the 8th element (index 7) of the original array.
slice() method does not modify the original array, it returns a new array. If you want to modify the original array, you can use the
splice() method instead.