Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var x = [
- '1',
- 12,
- [1, 2, { a: 'z' }],
- { a: 'zzz' }
- ]
- function ArrayToString(x) {
- var result = '[ '
- for(var i = 0; i < x.length; i++) {
- if(x[i].constructor === Object) {
- result = result + ObjectToString(x[i])
- } else if(x[i].constructor === Array) {
- result = result + ArrayToString(x[i])
- } else if(x[i].constructor === Function) {
- result = result + x[i].toString()
- } else {
- result = result + x[i]
- }
- if(x.length != i + 1) result = result + ', '
- }
- result = result + ' ]'
- return result;
- }
- function ObjectToString(x) {
- var result = '{ '
- for(var i in x) {
- if(x[i].constructor === Object) {
- result = result + i + ': ' + ObjectToString(x[i])
- } else if(x[i].constructor === Array) {
- result = result + i + ': ' + ArrayToString(x[i])
- } else if(x[i].constructor === Function) {
- result = result + i + ': ' + x[i].toString()
- } else {
- result = result + i + ': ' + x[i]
- }
- result = result + ', '
- }
- result = result + ' }'
- return result;
- }
- ArrayToString(x)
Add Comment
Please, Sign In to add comment