3 ms·
Ah, I see. Yeah, you would have to bind the argument to a name then destructure it separately: let foo = (bar) => { let {a, b, c} = bar return [bar,
by __ryan__ 4y ago
Ah, I see. Yeah, you would have to bind the argument to a name then destructure it separately:
let foo = (bar) => {
let {a, b, c} = bar
return [bar, a, b, c]
}
foo({ a: 1, b: 2, c: 3 }) // => [ { a: 1, b: 2, c: 3 }, 1, 2, 3 ]
Though JavaScript object keys are strictly strings and symbols, you can destructure dynamic keys like so:
let foo = (bar) => {
let {[1]: a, [2]: b} = bar
return [bar, a, b]
}
foo({ 1: "hi", 2: "world", 3: "!" }) // => [ { '1': 'hi', , '2': 'world', '3': '!' }, 'hi' 'world' ]