Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between push and pushObject in ember js

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?

like image 899
Hunt Avatar asked Oct 23 '25 19:10

Hunt


1 Answers

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.

like image 86
Gokul Kathirvel Avatar answered Oct 26 '25 09:10

Gokul Kathirvel