Thursday, May 22, 2014

Previous Interview Question Next Interview Question
Home

clone javascript object properties to another javascript object

In this i am trying to show how to clone an object properties to another object

First Object
var firstObject = {
    key1 : 'value1',
    key2 : 'value2'
};

Second Object
var secondObject = {
    key1 : 'value1',
    key2 : 'value2',
    key3 : 'value3',
    key4 : 'value4'
};

using below approach we can copy of objects properties to another object


for(var k in firstObject) secondObject[k]=firstObject[k];

Previous Interview Question Next Interview Question
Home

0 comments :

Post a Comment