Skip to content

Instantly share code, notes, and snippets.

@mrmlnc
Created March 30, 2017 14:41
Show Gist options
  • Save mrmlnc/dafcf847d006c4cfcc88f9cb6b19a9ff to your computer and use it in GitHub Desktop.
Save mrmlnc/dafcf847d006c4cfcc88f9cb6b19a9ff to your computer and use it in GitHub Desktop.
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