Node.js examples for Object:Property
Copy object by copying property by property
function copyObject( sourceObject /*= {}*/, propertyNames /*= getOwnProperties( sourceObject ) */ ) { if ( sourceObject === undefined ) sourceObject = {};/*from w w w. jav a2 s . c o m*/ if ( propertyNames === undefined ) propertyNames = getOwnProperties( sourceObject ); var newObject = {}; iterateArray( propertyNames, function ( propertyName ) { newObject[ propertyName ] = sourceObject[ propertyName ]; }); return newObject; } function getOwnProperties ( object ) { var array = []; for ( var propertyName in object ) if ( object.hasOwnProperty( propertyName ) ) array.push( propertyName ); return array; }