Object.assign

Copy the values of all of the enumerable own properties from one or more source objects to a target object and returns the target object.

Syntax

assign(target, ...source)

Parameters

Return value

The target object.

Examples

let currencies = {USD: '$', EUR: '€'}
let oldCurrencies  = {DEM: 'DM', FRF: 'F'}
Object.assign(currencies, oldCurrencies)
currencies
{USD: '$', EUR: '€', DEM: 'DM', FRF: 'F'}
let batteries = {AA: '1.5 V', AAA: '1.5 V', PP3: '9 V'}
let creditRatings = {AAA: 'prime', AA: 'high grade'}
let organizations = {AAA: 'American Automobile Association'}
Object.assign({}, batteries, creditRatings, organizations)
{ AA: "high grade", AAA: "American Automobile Association", PP3: "9 V" }