In our Angular7 frontend application, we are receiving a JSON response from the backend server. Response data is already sorted in the backend using some domain-specific logic.
Sample response
{
"a": ["test1", "test2"],
"b": ["test3", "test4"],
"c": ["test5", "test6"]
}
Now we want to display the response in HTML and we should not change the order of the JSON keys while displaying, we should maintain the same order what we received from the backend, just like below
a
test1
test2
b
test3
test4
c
test5
test6
I'm using the following code to achieve this but not sure whether it displays in the same order always or not
Object.entries(this.response).forEach(([key, value]) => {
response += `${key}\n`;
response += value.join('\n')+'\n\n';
});
How to maintain the original order while iterating&displaying JSON object in JavaScript