LoginSignup
0
1

More than 3 years have passed since last update.

Javascriptの分割代入

Posted at

配列の分割代入


let data = [10, 20, 30, 40, 50];
let [x0, x1, x2, x3, x4] = data

console.log(x0);
console.log(x1);
console.log(x2);
console.log(x3);
console.log(x4);
実行結果
10
20
30
40
50

オブジェクトの分割代入

let car = {manufacturer: "TOYOTA", color: "white", price: 2500000};
let {color, model, price} = car

console.log("color: " + color);
console.log("model: " + model);
console.log("price: " + price);
実行結果
color: white
model: undefined
price: 2500000
0
1
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
1