LoginSignup
0
0

More than 5 years have passed since last update.

【JavaScript 】分割代入

Posted at

分割代入

'use strict';

// 配列
const xyz = [1, 2, 3];
const [x, y, z] = xyz;
console.log(x); // 1
console.log(y); // 2
console.log(z); // 3

// スプレッド演算子
const arr = [10, 20, 30, 40, 50];
const [a, b, ...c] = arr;
console.log(a); // 10
console.log(b); // 20
console.log(c); // [30, 40, 50]

// オブジェクト
const obj = {
    oa: 10,
    ob: 20,
    oc: 30,
    od: 40,
}
const {oa, ob, ...cd} = obj;
console.log(oa); // 10
console.log(ob); // 20
console.log(cd); // {c: 30, d: 40}

※Google Chrome で確認
※ES8

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0