ibmpclp,
<script>
let list = {
value: 1,
next: {
value: 2,
next: {
value: 3,
next: {
value: 4,
next: null
}
}
}
};
function printList(list) {
var a = [list.value];
if (list.next) {
a = printList(list.next).concat(a);
}
return a
}
var a = printList(list);
document.write(JSON.stringify(a, null, 4))
</script>