Javascript Destructuring

const someArray = [3, 2, 31];
const arrayElement = someArray[1];
console.log(arrayElement); // 2
const someObject = {
someNumber: 12,
SomeString: "Hello,
};
const someProperty = someObject.someNumber;
console.log(someProperty); // 12

Destructuring arrays

const someArray = [1, 2, 3];
const [first, second] = someArray;
console.log(first); //1
Console.log(second); //2

Destructuring Objects

const someObject = {
someNumber: 12,
SomeString: "Hello",
};
const {someNumber, someString} = someObject;console.log(someNumber); // 12
console.log(someString); // "Hello"

Destructuring nested objects

const someObject = {
someNumber: 12,
nestedObject: {
nestedString: "Hello",
},
};
const {nestedObject: {nestedString}} = someObject;
console.log(nestedString); //"Hello"

Destructuring function parameters

const someObject = {
someNumber: 12,
SomeString: "Hello",
};
function someFunc({someNumber}) {
console.log(someNumber);
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Drill Into a JavaScript Object Safely With Optional Chaining

Feeding FileMaker

Stricter and Safer Type Guards in TypeScript

Ultimate Guide To Sanitize Request Body Before Saving To Database In NodeJS, ExpressJS with…

AEM Editable templates demystified.

Announcing NgRx Version 12: New operator for Effects, ComponentStore Enhancements, Integrated…

Content Provider for sharing ROOM Database using Kotlin

ROOM Component

How to use Datadog for monitoring and logging NodeJS on Heroku

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Roman Shnitser

Roman Shnitser

More from Medium

JavaScript & MongoDB

React vs. JavaScript

Asynchronous JavaScript

Popular JavaScript Frameworks