I am new to ember js. I want to know where to use arr.push() and arr.pushObject() in ember.js.What is the difference between them?
push is a vanilla javascript method to add an array entry. pushObject works exactly like push that adds an entry to the array plus it will notify the change to Ember so that the framework will re-render them if used in any dynamic context like a template, computed property etc.,
If you check this Twiddle, when you click push button, no changes will be reflected in the template. However, if you open the browser console, you can verify that the array has been mutated. This is because the push method will add entry but will not tell Ember about the changes hence Ember will not re-render the changes.
However, if you click the pushObject button, the array will be mutated as well as the changes will be reflected in the template.
If you want to track the changes you made to the array, it's apt to use pushObject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With