Utilizing the slice method allows you to extract a designated portion of an array, starting from one point (begin) and ending at another point (end). To create your own slice function, consider this approach:
function customSlice(array, begin, end) {
let slicedArray =[];
if(end===undefined || end > array.length)
end = array.length;
for (let i = begin; i < end; i++) {
slicedArray.push(array[i]);
}
return slicedArray;
}
mySlicedArray =customSlice([10,20,30,40],1,3);
In this example, we are extracting a slice from the array [10,20,30,40] starting at index 1 and ending at index 3, resulting in [20,30].