JSFiddle - React, Tailwind, and code Playground

by LeD4eG

JavaScript

var list = {
    value : 1,
    next: {
        value: 2,
        next: {
            value: 3,
            next: {
                value: 4,
                next: null
            }                
        }
    }        
};
    function reverseList(list){
        var arr=[];
        var listItem = list;
        while(listItem){
           arr.push(listItem.value);
           listItem = listItem.next;            
        }
        alert(arr.reverse());
    }

reverseList(list);