I have the following webservice call which I am using to populate a dropdown menu in the UI. I am getting these records in increasing number of createDate by the webservice if I am not using the reverse() method of Array. So I decided to use it in the following manner:
$.ajax({
beforeSend: function(request) {
request.setRequestHeader("eppn", emailID+"@abc.com");
},
url: 'http://localhost:8080/Services/getUserByDate?userid=JACK',
type : 'GET',
dataType:'json',
success : function(data) {
console.log("Sept 18 : Testing getUserByDate webservice");
console.log(data.usersList.reverse());
$.each(data.usersList.reverse(), function (i) {
$("#userSetList").append('<option><a href="#" >'+data.usersList[i].title+' | '+data.usersList[i].userSetId+' | '+moment(data.usersList[i].createDate).format('MM/DD/YYYY')+'</a></option>');
});
},
error : function(request,error)
{
$.growl.error({title: "Error", message: "Webservice request failed!" });
}
});
And noticed the following:
console.log("Sept 18 : Testing getUserByDate webservice");
console.log(data.usersList.reverse());
Above code showed the items in reversed format as expected. However, when I tested the following:
$.each(data.usersList.reverse(), function (i) {
$("#userSetList").append('<option><a href="#" >'+data.usersList[i].title+' | '+data.usersList[i].userSetId+' | '+moment(data.usersList[i].createDate).format('MM/DD/YYYY')+'</a></option>');
});
It’s not showing items in reverse order in the UI dropdown menu. Why?