Created
April 12, 2017 03:21
-
-
Save juliozuppa/6ac66f8402d2ce229facc9530e5e1c1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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