I'm trying to figure out what a piece of coding in FreeCodeCamp is doing, more specifically the method Object.keys(obj). The examples that are given documentation pertain to objects whose key id's are numbers. What I noticed is that the method orders the id's from smallest to largest, is that correct? If so what happens when the key id's are strings? Do they get ordered and if so how?
// array like object
var obj = { 0: 'a', 1: 'b', 2: 'c' };
console.log(Object.keys(obj)); // console: ['0', '1', '2']
// array like object with random key ordering
var an_obj = { 100: 'a', 2: 'b', 7: 'c' };
console.log(Object.keys(an_obj)); // console: ['2', '7', '100']
I'm trying to understand exactly what happens every step of the way with this code:
json.forEach(function(val) {
var keys = Object.keys(val);
html += "<div class = 'cat'>";
keys.forEach(function(key) {
html += "<strong>" + key + "</strong>: " + val[key] + "<br>";
});
html += "</div><br>";
});