let a = {
a: 1,
b: true
}
let b = {
y: 093,
z: 'This is an object'
}
const c = {...a, ...b}
let userName = { name: "John Doe" };
let userSex = { sex: "Male" };
let user = { ...userName, ...userSex };
console.log(user); // { name: "John Doe", sex: "Male" }
// Note: In a situation where one key has another property,
// the last property overrides the first instance:
let userName = { name: "John Doe" };
let userSex = { sex: "Female", name: "Jane Doe" };
let user = { ...userName, ...userSex }; // { name: "Jane Doe", sex: "Female" }
const person = {
name: "John Doe",
age: 24,
location: "U.S.A"
}
const job = {
title: "Full stack developer",
location: "Remote"
}
const employee = Object.assign(person, job);
console.log(employee);
//output
{
name: "John Doe",
age: 24,
location: "Remote",
title: "Full stack developer"
}
const person = {
name: "John Doe",
location: "Remote"
}
const job = {
title: "Full stack developer",
location: "Office"
}
const employee = {...person, ...job}
console.log(employee);
{
name: 'John Doe',
location: 'Office',
title: 'Full stack developer'
}