I have a good grasp of how to pass infinite parameters in a function in JavaScript.
But what about accepting any number of objects as parameters in a function?
This is my current implementation:
function merge<T>(objA: T, objB: T){
return Object.assign(objA, objB);
}
With this, I can use the function like this:
console.log(`${mergeObject2.age}, ${mergeObject2.name}`);
But how do you declare a function when the number of objects is unknown..?
For example, like this:
const mergeObject2 = merge({name: 'Niels'}, {age: 39}, {hobby: 'all'});
Thank you.
If I were to call the function like this:
const mergeObject2 = merge({name: 'Niels'}, {age: 39});
console.log(`${mergeObject2.age}, ${mergeObject2.name}`);
The output would be:
39, Niels
But how would you handle it with more objects..?