From 0da9be941f1caa8efaf1c5f18686314bf77d40c5 Mon Sep 17 00:00:00 2001 From: Frank Carlone III Date: Sun, 21 Oct 2018 16:58:39 -0400 Subject: [PATCH] Example using spread operator on object literals (#20970) Attached is my Hacktoberfest contribution (from Quincy Larson's article). --- .../javascript/es6/spread-operator/index.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/guide/english/javascript/es6/spread-operator/index.md b/guide/english/javascript/es6/spread-operator/index.md index 9a048c6acb..bb00fa9491 100644 --- a/guide/english/javascript/es6/spread-operator/index.md +++ b/guide/english/javascript/es6/spread-operator/index.md @@ -18,6 +18,25 @@ const arr_2 = [5, 6, 7, 8] const arr_final = [...arr_1, ...arr_2] // arr_final = [1, 2, 3, 4, 5, 6, 7, 8] ``` + +The spread operator can also copy enumerable properties from one or more objects onto a new object: +```javascript +const obj1 = { + a: 1, + b: 2, + c: 3 +}; + +const obj2 = { + d: 4, + e: 5, + f: 6 +}; + +const newObj = {...obj1, ...obj2); + +// newObj = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 } +``` ### More Information: - [MDN - Spread Syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)