How do I copy a JavaScript object into another object?
- by Josh K
Say I want to start with a blank JavaScript object:
me = {};
And then I have an array:
me_arr = new Array();
me_arr['name'] = "Josh K";
me_arr['firstname'] = "Josh";
Now I want to throw that array into the object so I can use me.name to return Josh K.
I tried:
for(var i in me_arr)
{
me.i = me_arr[i];
}
But this didn't have the desired result. Is this possible? My main goal is to wrap this array in a JavaScript object so I can pass it to a PHP script (via AJAX or whatever) as JSON.