JSFiddle - React, Tailwind, and code Playground
by vinodlouis
JavaScript
//objSynchTo --> New Object
//objSynchFrom --> the old object containing all properties
//arySynchToProperties --> properties name you want in new object
//arySynchFromProperties --> the relevant properties in old object
function fnCopyObjects(objCopyTo, objCopyFrom, aryCopyToProperties, aryCopyFromProperties)
{
if (objCopyTo == null)
objCopyTo = new Object();
for (var intIndex = 0; intIndex < aryCopyFromProperties.length; intIndex++)
{
var strPropertyName = aryCopyFromProperties[intIndex];
if (objCopyFrom[strPropertyName] == undefined) // Requested property isn't defined into source object.
continue;
var strToPropertyName = aryCopyToProperties[intIndex];
objCopyTo[strToPropertyName] = objCopyFrom[strPropertyName];
}
}
var A={a:1,b:2,c:'e',d:'t'};
var B={};
fnCopyObjects(B,A,['a','b','d'],['a','b','d']);
console.log(B);