Can Ember.A() contain numbers/strings or it is suitable only for objects?


#1

I’m trying to find out if Ember.A() can be used also with non-Objects. In the documentation, ethe strings are used in Enumerables together with pushObject() [e.g. in https://guides.emberjs.com/v2.16.0/object-model/enumerables/]

But when I try to add an empty string (as with push()), the value is not added. When I try to do replace, the item is removed from the array.

let arr = Ember.A(['first', 'second', 'third']);

arr.replace(0, 1, 'new-first');
arr.replace(1, 1, '');

#2

try with pushObject https://emberjs.com/api/ember/2.14/classes/Ember.MutableArray/methods/pushObject?anchor=pushObject


#3

Thanks, pushObject() works as expected that makes it inconsistent. Originally, I had code with pushObject but then I shortened it to array initialization.

I need to replace/remove items from inside the array, so push(pop)Object does not work for me that well.


#4

So, third parameter have to be collection. In later versions, you will see an assert that will warn you about it (thanks to Serabe and his PR#15814).

Solved.

Correct solution is:

arr.replace(1, 1, ['']);