How do I copy a JavaScript object into another object?
Posted
by Josh K
on Stack Overflow
See other posts from Stack Overflow
or by Josh K
Published on 2010-05-11T15:25:48Z
Indexed on
2010/05/11
15:34 UTC
Read the original article
Hit count: 590
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.
© Stack Overflow or respective owner