I have a simple object (or hash) in Javascript:
var settings = {
link: \'http://example.com\',
photo: \'http://photos.com/me.jpg\'
};
I nee
In a non jQuery way.
var newObj = {};
Object.keys(settings).forEach(function(key) {
newObj[ key ] = settings[ key ];
});
This copies only the top-level properties. To copy hashes with nested objects as property values, you will need to use a recursive function.
NB: The Object.keys(settings)
avoids the need for calling settings.hasOwnProperty(key)
.