xxxxxxxxxx
// Closest solution to python's enumerate function is the combo of for-of loop and
// Object.entries() function:
// By the way, you can do the same with arrays, instead you will get a pair of
// [index, value]
var object = {
key1: "value1",
key2: "value2",
key3: "value3",
};
// or
var object = ["value1", "value2", "value3"];
// just the key will be index for arrays
for(let [key, value] of Object.entries(object)) {
// Do something ...
}
// Or if you are that much used to python, then you could just create a function called
// enumerate and use it the same way:
function enumerate(obj) {
return Object.entries(obj);
}
for(let [key, value] of enumerate(object)) {
// Do something ...
}