JSFiddle - React, Tailwind, and code Playground
by Dmitri Ganenco
JavaScript
var a1 = {
name: "Mike",
email: "[email protected]",
gender: "1",
hobby: ["travel", "movie"]
}
var a2 = {
personal_information: {
name: null,
password: null,
gender: null
},
business_information: {
email: null,
id: null,
},
special_information: {
hobby: null,
achievement: null
}
}
const arr = Object.keys(a2).reduce((a, key) => {
Object.keys(a2[key]).forEach(value => {
if(a1.hasOwnProperty(value)){
a[key] = a[key] || {};
a[key][value] = a1[value];
}
});
return a;
}, {});
console.log(arr);