Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 16, 2019 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/4d9e2122108dc6181f1f80c3bfe455ff to your computer and use it in GitHub Desktop.
Save parzibyte/4d9e2122108dc6181f1f80c3bfe455ff to your computer and use it in GitHub Desktop.
/**
* Convertir un objeto a un arreglo
* en JavaScript
*
* @author parzibyte
*
* https://parzibyte.me/blog
*/
let alumnosConCalificaciones = {
"Luis": 100,
"Pedro": 90,
"María José": 100,
"John Galt": 99
};
// Object.entries convierte tanto clave y valor. Cada
// par es convertido a un arreglo. Al final tenemos un array de arrays
let arregloDeClavesYValores = Object.entries(alumnosConCalificaciones);
console.log("Claves y valores: ", arregloDeClavesYValores);
/*
Salida:
Claves y valores: [ [ 'Luis', 100 ],
[ 'Pedro', 90 ],
[ 'María José', 100 ],
[ 'John Galt', 99 ] ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment