Create an object with javascript reflection?
Posted
by acidzombie24
on Stack Overflow
See other posts from Stack Overflow
or by acidzombie24
Published on 2010-05-31T10:53:00Z
Indexed on
2010/05/31
15:03 UTC
Read the original article
Hit count: 183
JavaScript
I am doing something wrong. At the end of this o is empty. I want to pass in a string such as a=3&zz=5
and do o.a and o.zz to retrieve 3 and 5. How do i generate this object?
function MakeIntoFields_sz(sz) {
var kvLs = sz.split('&');
var o = new Array();
for (var kv in kvLs) {
var kvA = kvLs[kv].split('=');
var k = '';
var v = '';
if (kvA.length > 0) {
k = kvA[0];
if (kvA.length > 1)
v = kvA[1];
o[k] = v;
}
}
return o;
};
© Stack Overflow or respective owner