abdul-wahab
abdul-wahab

Reputation: 2272

What does braces "{ }" inside argument of an arrow function mean

I know, for multiple arguments or single argument with type, we have to parenthesize arguments of an arrow function. e.g.

.map( (arg1, arge2) => returnValue ) or .map( (arg1: ArgType) => returnValue )

And if we intend to return a json literal from shorter syntax arrow function, we've to parenthesize it. e.g.

.map( (arg1, arge2) => ({ a: 1, b: 2}) )

But, what does the following do?

.map( ({ value }) => value )

I stumbled across it in a TypeScript codebase, don't yet know if it is also supported in ES6.

Upvotes: 2

Views: 118

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 250056

This is part of destructuring in ES2015 it is basically equivalent to

let arr = [{ value: "" }]
arr.map(({ value }) => value )
// same as 
arr.map(o => { let value = o.value; return value; }  )

Upvotes: 4

Related Questions