Skip to content

Instantly share code, notes, and snippets.

@Heavyblade
Created February 6, 2020 19:38
Show Gist options
  • Save Heavyblade/df2fec5763fe0f234347c012041c40cb to your computer and use it in GitHub Desktop.
Save Heavyblade/df2fec5763fe0f234347c012041c40cb to your computer and use it in GitHub Desktop.
iteracion.js
const items = {
"item_1": 1,
"item_2": 2,
"item_3": 3,
"item_4": 4,
"item_5": 5,
"nombre": "cristian",
"apellido": "vasquez"
};
console.log("xxxxxxxxxxxxxxx Iteracion each xxxxxxxxx ")
for (i in items) {
console.log("Key: [" + i + "], valor: " + items[i]);
}
console.log("xxxxxxxxxxxxxxx Iteracion por los keys xxxxxxxxx ")
const keys = Object.keys(items);
let x = keys.length;
for(i = 0; i<x; i++) {
console.log("Key: [" + keys[i] + "], valor: " + items[keys[i]]);
}
console.log("xxxxxxxxxxxxxxx Solo os items xxxxxxxxx ")
for(i=1; i <= 5; i++) {
console.log("Key: [item_" + i + "], valor: " + items["item_" + i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment