As @Niko notes in a comment, JavaScript has no associative arrays.
In fact, you are setting the properties of an array object, which is not a good idea. You will be better off using the actual object.
var some_db = {}; some_db["One"] = "1"; some_db["Two"] = "2"; some_db["Three"] = "3"; var copy_db = {}, prop; // loop over all the keys in the object for ( prop in some_db ) { // make sure the object has this value, and not its prototype if ( some_db.hasOwnProperty( prop ) ) { copy_db[ prop ] = some_db[ prop ]; } }
Many libraries implement the extend function, which does just that (copies keys from one object to another). Most noticeable are jQuery and underscore.js . The underline also has _.clone( obj ) , which is effectively _.extend( {}, obj )
gnarf
source share