Destructuring assignment in JS

Simple ones javascript const [a, b, ...c] = [10, 20, 100,200] // a= 10, b=20, c=[100,200] const { first, second } = { first: 1, second: 2 } // first = 1, second = 2

Crazier one javascript const resp = { data: { message: 'hello', random: 'xxx', test:'hehe' } } const { data, data: { message, ...rest } = resp // data = { message: 'hello' }, message = 'hello' // rest = { random: 'xxx', test: 'hehe' }

Tino

Get our stories delivered

From us to your inbox weekly.