JSFiddle - React, Tailwind, and code Playground
JavaScript
function Node(data) {
this.data = data;
this.next = null;
}
function getNth(node, index) {
if(node.data === index+1){
return node.data;
}else if(typeof node.next == 'object'){
return getNth(node.next, index);
}else{
return false
}
}
console.log(getNth(new Node(1), 0));