分割代入とは

ECMAScript 2015 で定義された構文。

分割代入 (Destructuring assignment) 構文は、
配列から値を取り出して、あるいはオブジェクトからプロパティを取り出して別個の変数に代入することを可能にする JavaScript の式である。

オブジェクトと分割代入

example.js
const user = {name:'Tanaka', age:20, job:'student'} const {name, job} = user; console.log(name); // 'Tanaka' console.log(job); // 'student'

分割代入を用いることで、その後に変数を使用する際に短い記述で実現できる。

関連

参考

https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment external_link