Recently, I've been delving into the world of javascript and encountered a task that involves removing the first item from an array.
Solution One
function getFirst(arr, item) {
arr.push(item);
var removed = arr.shift();
return removed;
}
Solution Two
function getFirst2(arr, item) {
arr = arr.push(item);
var removed = arr.shift();
return removed;
}
I came up with these two solutions, but only the first method was accepted. The second method resulted in an error stating "Uncaught TypeError: arr.shift is not a function()."
Can someone explain the exact meaning of Uncaught TypeError and why arr.shift works for Method one but not Method two?
Any assistance would be greatly appreciated! Thank you!