JavaScript Error – How to Fix ‘Cannot Read Property ‘Push’ of Undefined’

arraydata-pushjavascript

When pushing an array's contents i get
enter image description here

here is my code
enter image description here

Best Answer

This is because the context of this has changed within your each. Try this:

const self = this;

$.each(res, function(index, value) {
    self.qtyOptions.push(value);
}
Related Topic