JavaScript error says "confirm is not a function"
If you assign a variable without var, you are assigning that variable to the global space. In your case there was a string assigned to the confirm variable that overrode the native confirm method.
The confirm function is part of the window object.
if (window.confirm(key)){
console.log(item);
}