I would like to merge all objects in one array into one object, with a custom function. Using lodash's mergeWith works well:
let a = [{a: [1,2]}, {a:[3,4]}, {a: [7,8]}]
let b = mergeWith(
a[0],
...a.slice(1),
(objValue: any, srcValue: any) => {
if (Array.isArray(objValue)) {
return objValue.concat(srcValue);
}
},
);
console.log(b);
// result: {a:[1,2,3,4,7,8]}
This works fine but it seems wasteful to create an array copy just for that (a.slice(1)) - is there another way to pass that array to mergeWith?