EDIT: I filed an error , don't be shy +1
ECMAScript does not indicate the order in which keys should be iterated, however, all major browsers implement objects as a related hash map (preserves order), and many js libraries depend on this behavior, and therefore we are used to it, and this is unlikely to change.
Angular on the other hand (this is completely unexpected ) sorts it alphabetically. I myself checked the source code, it is hardcoded, and it would be nice if it were resolved one day. Otherwise, the function (k, v) in obj completely useless .
You really can't do anything with this, tricking angular to think that your result - an array is not useful for anything, because then you will need the number keys ...
If this is normal, you can define a getter for the length:
Object.defineProperty(yourResultObjectOrPrototype, 'length', { get: function(){ return Object.keys(this).length; } })
Otherwise, you will need some kind of filter that will iterate over the object using for(var k in obj) and save the result in an array.
Kamil TomΕ‘Γk Feb 11 '14 at 10:33 2014-02-11 10:33
source share