Skip to content

Instantly share code, notes, and snippets.

@rdeprey
Last active April 2, 2019 00:00
Show Gist options
  • Save rdeprey/d25875373f5f05a580761901026dea14 to your computer and use it in GitHub Desktop.
Save rdeprey/d25875373f5f05a580761901026dea14 to your computer and use it in GitHub Desktop.
Converting an object to an array using a for... in loop
const taco = {
tortillaType: 'corn',
meat: 'chicken',
toppings: 'lettuce, cheese, tomatoes',
};
const tacoArr = [];
for (value in taco) {
tacoArr.push([value, taco[value]]);
}
console.log(tacoArr); // expected output: [['tortillaType', 'corn'], ['meat', 'chicken'], ['toppings', 'lettuce, cheese, tomatoes']]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment