how to see all object attributes?
|
| View previous topic :: View next topic |
| Author |
Message |
AmeliaR
Joined: 31 May 2006 Posts: 142
|
How do I see all object attributes/properties ?
I try for (x in arr){ alert(arr[x]);}
But it shows only value |
| |
|
|
|
|
Kopilman
Joined: 25 May 2006 Posts: 162
|
| AmeliaR, alert(x + " " + arr[x]) would show keys as well |
| |
|
|
AmeliaR
Joined: 31 May 2006 Posts: 142
|
Uuh
ThanAmeliaR |
| |
|
|
Kopilman
Joined: 25 May 2006 Posts: 162
|
| But I don't have a nicer solution that doesn't involve tons of alerts. |
| |
|
|
AmeliaR
Joined: 31 May 2006 Posts: 142
|
Can I concatenate all pairs in a string ?
Like alert (concat(o)) ?
So it shows k=>v pairs |
| |
|
|
Kopilman
Joined: 25 May 2006 Posts: 162
|
| As far as I know, Javascript lacAmeliaR reduce(), map(), etc. |
| |
|
|
AmeliaR
Joined: 31 May 2006 Posts: 142
|
| Pity |
| |
|
|
Lusis Backwood JR
Joined: 26 May 2006 Posts: 87 Location: United States
|
Function foo(o) { var a = []; for(var p in o) a.push(p); a.sort(); for(var i = 0; i < a.length; i++) a[i] = a[i]+'='+o[a[i]]; alert(a.join('\n')); }
Foo(someobject); |
| |
|
|
AmeliaR
Joined: 31 May 2006 Posts: 142
|
| Neat |
| |
|
|
|
|