Skip to content

Instantly share code, notes, and snippets.

@juliozuppa
Created April 12, 2017 03:21
Show Gist options
  • Save juliozuppa/6ac66f8402d2ce229facc9530e5e1c1f to your computer and use it in GitHub Desktop.
Save juliozuppa/6ac66f8402d2ce229facc9530e5e1c1f to your computer and use it in GitHub Desktop.
var obj = {
id: 11, nome: 'Julio',
test: {id: 1, nome: 'test'}
};
var arrayFromObject = function (obj) {
var arr = [];
for (var i in obj) {
arr[i] = (typeof obj[i] === 'object') ?
arrayFromObject(obj[i]) : arr[i] = obj[i];
}
return arr;
}
var arr = arrayFromObject(obj);
console.log(arr['id']); // 11
console.log(arr['nome']); // Julio
console.log(arr['test']); // [id: 1, nome: "test"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment