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;
};
<script>
element in an XHTML file may balk at the unescaped&
, no?alert(o)
, which seems to be empty. If I put a breakpoint after executing this function and I delve into the array, I see the correct values. Just tryalert(o.a + ", " + o.zz)
.console.log
which prints out the whole object in a nice little explorable way (like Firebug does). It also showed that this algorithm works fine as-is.