Copy and Merge

Copy

Use the wire.copy function to make a deep copy of an object or Array.
1
let data = { product: "SKU001", month: "May", sales: 300 }
2
3
const dataCopy = wire.copy(data);
Copied!

Merge

Use the wire.merge function to merge the values of one object into another. This function take two parameters. The first is the target and the second is the source. All properties and their values on the source object will be copied into the target object. If a target property already exists, it will be overwritten by the same on the source. If not, it will be left alone.
In the example below, the target variable values of product and sales will be replaced with those from the source variable but will leave the month attribute alone.
1
let source = { product: "SKU001", month: "May", sales: 300 }
2
let target = { product: "SKU431", sales: 500 }
3
4
wire.merge(target, source);
5
6
// target = { product: "SKU001", month: "May", sales: 300 }
Copied!
Copy link
Contents
Copy
Merge