The extend() method can be used to create objects dynamically from other objects passed in as arguments. In your case, it looks like the objects in the ‘$Array’ field do not have overlapping keys, so you can directly use the array as the arguments to extend
. However, you cannot just pass ‘$Array’ to extend()
, you need to use the spread operator to indicate that the elements of the array should be treated as the arguments to the function, like so:
{}.extend(...$Array)
The {}
part just creates an empty object for us to call extend()
on.
There are a few other examples of using the extend()
method in the community, like this one.