I ran into this problem and am unable to figure out why and couldn't find any explanation on google. I have a $http.get method to retrieve some data from a url, on success i am sorting the response. But when I run the page on google chrome, I get the error "TypeError: response.sort is not a function"
var orderOfGroups = ["alpha", "beta", "gamma", "delta"];
$http.get(url)
.success( function (response, status, headers, config) {
response.sort( function(a, b) {
var aname = orderOfGroups.indexOf(a.team);
var bname = orderOfGroups.indexOf(b.team);
return bname-aname;
});
});
I am getting the error at "response.sort" line. Also this is happening only in google chrome, I tested it in firefox and IE10, and its working fine on these browsers. The json data I am receiving (response) has the following format
[
{
team: "gamma",
value: "p"
},
{
team: "alpha",
value: "q"
},
......
]
Could you please tell me how I can resolve this?
Your response
is not an Array. It could be an object with a property that contains the Array (e.g. response.data
) or a string version of you array and then you will need to use JSON.parse
and convert the string into an Array.
Anyway, sort is on Array's prototype - that means that all the arrays will have that property on them - This is not related to AngularJS
or google chrome
.
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