I'm encountering annoying issues. I'm struggling on it for many hours.
I need to render my data (fetched by an ajax call) ordered by the value date
So the JSON looks like
user_a:
{ message:
{ text: 'Hello',
date: 1547093749649,
},
user_b:
{ message:
{ text: 'Hi',
date: 1547093749639,
}
}
When my JSON come from the database, the object with text: Hello
is always at the top. But surprisingly when I want to display the data with some HTML, the render is displayed randomly. sometimes user_b come first, other time this is user_a.
I've also tried to rebuild the object by generating a new one based on js sorting method
sortable.sort(function(a,b){
return b - a
})
but no effect.
Maybe it's related to my iteration method
var html = '<div>'
Object.keys(object).map((node,i) => {
html =+ '<p>'+object[node]['message']['text']+'</p>'
})
html =+ </div>
I'm confused and I don't know how to force HTML to render my object keys/value in the same order than the JSON obj.