Please refer to fiddle js file object obj1. (I'm starting out with an object this format because it represents what I get back from Ajax when PHP echos back an ordered key,value PHP array).
var obj1 = {
"key1": "val1",
"key2": "val2",
"key3": "val3"
};
box1.innerText = "Object: " + JSON.stringify(obj1);
var arr1 = [];
for( keystr in obj1 ) {
box2.innerText = keystr;
valstr = obj1[keystr];
arr1.push({keystr : valstr});
}
box3.innerText = "Array: " + JSON.stringify(arr1);
For those who ask why I'm trying to do this: Because I want to see if I can preserve the order (I have heard js objects are not ordered?) and because it happens to be the format needed for the function argument I'm going to pass the data to next.
As you can see what is happening, the identifier (i.e. "keystr") is getting used for the key, instead of the string itself (i.e. "key1", "key2", "key3").
What approach is recommended here? Thanks!