Created
March 30, 2017 14:41
-
-
Save mrmlnc/dafcf847d006c4cfcc88f9cb6b19a9ff to your computer and use it in GitHub Desktop.
This file contains 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 data = { | |
value: 123, | |
next: { | |
value: 321, | |
next: { | |
value: 348, | |
next: { | |
value: 981, | |
next: { | |
value: 712, | |
next: { | |
value: 331 | |
} | |
} | |
} | |
} | |
} | |
}; | |
function objToArray(obj: object): any[] { | |
const result = []; | |
let current = obj; | |
while (current) { | |
result.push(current.value); | |
current = current.next; | |
} | |
return result; | |
} | |
console.log(objToArray(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment