I am trying to implement a stack. when I try to push into the arr this error pops up
TypeError: Cannot read property 'push' of undefined
var MinStack = function() {
let Min = null;
const arr = new Array(); // I also tried arr = []
};
/**
* @param {number} x
* @return {void}
*/
MinStack.prototype.push = function(x) {
this.arr.push(x);
this.Min = Math.min(...arr);
};
I searched for answers but I didn't find out why can't I access my arr in the constructor?