Okay, I think my problem is a common Javascript thing.
A have a simple ajax call with a success callback.
The ajax call returns a list of products. Now I need a list of these products sorted by Id and sorted by Date.
The list of products contains objects like this one:
{
Id: 12345,
LastModified: "2015-01-05T14:53:18.493Z",
Name: "Beer"
}
Here is my sample code:
var prodsAll;
var prodsNew;
$.ajax({
url:"getProds.php",
success:function(res) {
prodsAll= res;
prodsNew = res;
prodAll.sort(function (a, b) {
return a.Id > b.Id ? 1 : -1;
});
prodNew.sort(function (a, b) {
return new Date(b.LastModified).getTime() - new Date(a.LastModified).getTime();
});
}
});
Whatever I do, it looks that all of my lists are changed!?
When I do:
console.log(res);
console.log(prodsAll);
console.log(prodsNew);
I always get the same result :-/
How is it possible to change the lists independent!?