From c7ce87090f37054bf8142bb9c1a916d81bcc5133 Mon Sep 17 00:00:00 2001 From: Ragunathan Maniraj Date: Tue, 16 Oct 2018 09:21:09 +0530 Subject: [PATCH] destructuring an array in ES6 rest (#19424) * destructuring an array in ES6 rest * fix: added const on line 56 --- .../guide/english/javascript/es6/destructuring/index.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/pages/guide/english/javascript/es6/destructuring/index.md b/client/src/pages/guide/english/javascript/es6/destructuring/index.md index 304b17e7f3..eee2b88f3f 100644 --- a/client/src/pages/guide/english/javascript/es6/destructuring/index.md +++ b/client/src/pages/guide/english/javascript/es6/destructuring/index.md @@ -53,7 +53,7 @@ console.log(firstName, lastName); // undefined undefined You can still achieve the desired result using the following syntax. ```js const obj = {propertyName: value} -{propertyName: desiredVariableName} = obj +const {propertyName: desiredVariableName} = obj ``` Our previous example would be rewritten as follows: @@ -63,3 +63,10 @@ const {first: firstName, last: lastName} = fullName; console.log(firstName, lastName); // John Smith ``` +**Array Destructuring with rest** +When destructuring an array, you can unpack and assign the remaining part of it to a variable using the rest pattern: +```js +const [a, ...b] = [1, 2, 3]; +console.log(a); // 1 +console.log(b); // [2, 3] +```