fork download
  1. var arr=[
  2. {title:"first",submenu:[{title:"ek"},{title:"do"},{title:"teen"}]},
  3. {title:"second"},
  4. {title:"third"}
  5. ];
  6. var ul=document.createElement('ul');
  7. document.body.appendChild(ul);
  8. for(var i=0;i<arr.length;i++)
  9. {var li=document.createElement('li');
  10. li.innerHTML=arr[i].title;
  11. ul.appendChild(li);
  12.  
  13. if (arr[i].submenu)
  14. {
  15. var ul2=document.createElement('ul');
  16. //li[i].appendChild(ul2);
  17. li.appendChild(ul2);
  18. for(var j=0;j<arr[i].submenu.length;j++)
  19.  
  20. {
  21. var li2=document.createElement('li');
  22. //li2.innerHTML=arr[i].title;
  23. li2.innerHTML=arr[j].title;
  24. ul2.appendChild(li2);
  25. }
  26.  
  27. }
  28. }
Runtime error #stdin #stdout #stderr 0.02s 30432KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:6:0 ReferenceError: document is not defined