宇井隆治  2020/12/20更新

分割代入


値の交換

let x = 70;

let y = 30;

[x, y] = [y, x]

console.log(x);     //30

console.log(y);    //70


const foo = ['one', 'two', 'three'];

const [red, yellow, green] = foo;

console.log(red); // "one"

console.log(yellow); // "two"

console.log(green); // "three"

タイトルとURLをコピーしました