You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Steve Schwarz <sa...@hotmail.com> on 2003/08/11 21:48:38 UTC

Re: Copy javascript maps

>I have two javascript maps:
>
>var map1 = { x : y };
>var map2 = { a : b };
>
>I want to copy both maps into one single map. Does anybody have an idea
>how I can achieve this?

Object properties in JavaScript can be treated just like arrays:

<script type="text/javascript">
onload=function(){
var map1 = { x : 1 };
var map2 = { a : 2 };
var newMap = new Object();
copyProp(newMap, map1);
copyProp(newMap, map2);

function copyProp(dest,src){
for (var i in src) dest[i] = src[i];
};

function dumpProp(obj){
var str ="";
for (var i in obj)  str += obj[i]+" ";
return str;
};

alert(dumpProp(newMap));
}
</script>

Hope this helps
Steve

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org