Object.assign()

ES6+

Copies all enumerable own properties from one or more source objects to a target object.

Syntax

Object.assign(target, ...sources)

Parameters

target Object

The target object to copy to

sources Object

The source object(s) to copy from

Return Value

Object

The target object

Examples

JavaScript
const target = { a: 1 };
const source = { b: 2, c: 3 };
const result = Object.assign(target, source);
console.log(result);
Output:
// { a: 1, b: 2, c: 3 }

Related Methods