[Solved] javascript slice without using built in method [closed]


With the slice method you are just extracting a ‘slice’ of the array starting from here (begin) to there (end). To implement the slice function yourself try something like this:

function newSlice(array, begin, end) {
  let tempArray =[];

  if(end===undefined || end > array.length)
    end = array.length;

  for (let i = begin; i < end; i++) {
    tempArray.push(array[i]);
  }
  return tempArray;
}

myArray =newSlice([8,3,4,5,4],1,3);

Here we get a slice from array [8,3,4,5,4] from index 1 to end at index 3 returning [3,4].

3

solved javascript slice without using built in method [closed]