Javascript version of list.pop

are you looking for something like this? maybe you can modify it so that the pop function returns the removed element.

const arr1 =  [10,20,30,40,50,60];
const arr2 =  [10,20,30,40,50,60];
const arr3 =  [10,20,30,40,50,60];

function pop(arr, idx) {
    removedEl = arr.splice(idx,1)[0];
  console.log('removed element: ',removedEl)
  console.log('final array: ',arr);
}

pop(arr1,0);
pop(arr2,2);
pop(arr3,5)