I have a JSON object that has different keys in one long single object (> 10,000 lines). How can I iterate through each key and display the key in one div and its value in another div using js?
I have a variable holding this object and console logging them I can see them as they should be. But my problem lies in grabbing each one since the keys are always different. Normally el.key will get the key/value you are after but since the key is always changing from pair to pair how can I access all keys and send them to the div#keys and then grab all the values and send them to div#values?
Here's a snippet of the JSON object:
{
10: 1
11: 1
13: 1
15: 1
20: 1
21: 2
22: 2
25: 2
28: 3
32: 1
33: 3
37: 1
38: 1
39: 2
41: 1
45: 2
}
Sample html:
<div id="keys">keys go here</div>
<div id="values">values go here</div>
Thanks,
Sergio
k = Object.keys(obj);andv = k.map(x => obj[x]);. jsfiddle