How to merge objects in TypeScript

1 Answer

0 votes
const obj1 = { name: 'r2d2', age: 70 };
const obj2 = { skill: 'hacker' };

const obj3 = { ...obj1, ...obj2 };

console.log(obj3); 
   
   
   
   
/*
run:
 
{
  "name": "r2d2",
  "age": 70,
  "skill": "hacker"
} 
   
*/

 

 



answered Feb 21, 2022 by avibootz
...