I have a response object, which has a key tags whose value is a json. I am trying to sort the json based on a key, then iterating through the list and pushing the objects to a react list. I see that when I print individually, they are coming as expected, but when I print as a whole, they are not in the same order.
sortTags: function (response) {
tagss = []
response.tags.sort((a, b) => a.disp_id - b.disp_id).map(function(tag) {
console.log(tag)
tagss.push(tag)
});
console.log(tagss)
return tagss;
}
I see that when I do console.log(tag)
, it is printing in the order as expected. But console.log(tagss)
is printing in a different order.
The question maybe very naive. Please do help. Thank you, in advance.