LoginSignup
1
0

More than 5 years have passed since last update.

【JavaScript 】スプレッド演算子

Posted at

スプレッド演算子

'use strict';

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

// 値はコピーされている
x[1] = 5;
console.log(x); // [3, 5]
console.log(y); // [1, 2, 3, 4]

// オブジェクト
const ox = {x: 1};
const oy = {y: 2};
const oz= {...ox, ...oy}
console.log(oz); // {x: 1, y: 2}

// 引数
const xyz = [1, 2, 3];
const sum = (x, y, z) => x + y + z;
console.log(sum(...xyz)); // 6

※Google Chrome で確認
※ES8

1
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
1
0