fork download
  1. // AS-IS
  2. let bfArr = ['nodejs', {}, 10, true];
  3. let bfNode = bfArr[0];
  4. let bfObj = bfArr[1];
  5. let bfBool = bfArr[3];
  6.  
  7. // TO-BE : 배열에 대한 구조분해 할당
  8. let afArr = ['nodejs', {}, 10, true];
  9. let [afNode, afObj, , afBool] = afArr; // 1, 2, 4번째 요소를 변수에 대입
  10.  
  11. console.log('bfNode', bfNode);
  12. console.log('bfObj', bfObj);
  13. console.log('bfBool', bfBool);
  14.  
  15. console.log('afNode', afNode);
  16. console.log('afObj', afObj);
  17. console.log('afBool', afBool);
Success #stdin #stdout 0.03s 16744KB
stdin
Standard input is empty
stdout
bfNode nodejs
bfObj [object Object]
bfBool true
afNode nodejs
afObj [object Object]
afBool true