[TypeScript] Destructuring and Spread
Array Destructuring let input = [1, 2]; let [first, second] = input; console.log(`${first}, ${second}`); // 1, 2 Multiple values of an array can be easily assigned as variables. function f([first, second]: [number, number]) { console.log(`${first}, ${second}`); } f([1, 2]) // 1, 2 It can be also applied in the parameters of a function. let [first, ...rest] = [1, 2, 3, 4]; console.log(first); // ..
2020. 10. 16.