Reputation: 28076
I've got to the point where I have started using Array
functions inside of my Phonegap app.
I am running KickCat 4.4.2
with my Nexus 5, my Nexus 4 also suffers from the same problem.
But to my shock horror it seems that which ever browser phonegap is using it does not have any of the array functions defined.
Array()
[]
Array.reverse
undefined
Array.join
undefined
Array.push
undefined
So Array
is a function, but anything more does not exist.
Is there anyway to active or use these functions?
The actual function I'm after is Array.reverse
.
Upvotes: 0
Views: 714
Reputation: 123473
Uncaught TypeError: Object function Array() {[native code]} has no method 'reverse'
when runningArray.reverse(Object.keys(data))
If you'd like to reverse the collection returned by Object.keys()
, the collection will be an Array
so you can simply chain the call to .reverse()
:
var reversedKeys = Object.keys(data).reverse();
The error is because Array.reverse()
doesn't exist and typically won't. The standard Array
methods are actually defined as properties of Array.prototype
rather than as properties of Array
itself.
Though, you can define it so it's available from both:
Array.reverse = function (collection) {
return Array.prototype.reverse.call(collection);
};
var reversedKeys = Array.reverse(Object.keys(data));
Upvotes: 1