Guest User

Untitled

a guest
Jan 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. var x = [
  2. '1',
  3. 12,
  4. [1, 2, { a: 'z' }],
  5. { a: 'zzz' }
  6. ]
  7.  
  8.  
  9. function ArrayToString(x) {
  10. var result = '[ '
  11. for(var i = 0; i < x.length; i++) {
  12. if(x[i].constructor === Object) {
  13. result = result + ObjectToString(x[i])
  14. } else if(x[i].constructor === Array) {
  15. result = result + ArrayToString(x[i])
  16. } else if(x[i].constructor === Function) {
  17. result = result + x[i].toString()
  18. } else {
  19. result = result + x[i]
  20. }
  21. if(x.length != i + 1) result = result + ', '
  22. }
  23. result = result + ' ]'
  24. return result;
  25. }
  26.  
  27.  
  28. function ObjectToString(x) {
  29. var result = '{ '
  30. for(var i in x) {
  31. if(x[i].constructor === Object) {
  32. result = result + i + ': ' + ObjectToString(x[i])
  33. } else if(x[i].constructor === Array) {
  34. result = result + i + ': ' + ArrayToString(x[i])
  35. } else if(x[i].constructor === Function) {
  36. result = result + i + ': ' + x[i].toString()
  37. } else {
  38. result = result + i + ': ' + x[i]
  39. }
  40. result = result + ', '
  41. }
  42. result = result + ' }'
  43. return result;
  44. }
  45.  
  46. ArrayToString(x)
Add Comment
Please, Sign In to add comment