JavaScript တွင် Object များကို Destructuring လုပ်ခြင်း

Object များကိုလည်း destructuring လုပ်နိုင်ပါသည်။ ဥပမာအားဖြင့်၊ ကျွန်ုပ်တို့တွင် အောက်ပါ object ရှိသည်ဟု ဆိုကြပါစို့-

javascriptlet obj = {
  year:  2025,
  month: 12,
  day:   31,
};

၎င်း၏ destructuring ကို လုပ်ကြည့်ရအောင်။

javascriptlet obj = {
  year:  2025,
  month: 12,
  day:   31,
};

let {year, month, day} = obj;

console.log(year);  // 2025 ကိုပြမည်
console.log(month); // 12 ကိုပြမည်
console.log(day);   // 31 ကိုပြမည်

Object များကို destructuring လုပ်ရာတွင် variable အမည်များသည် object ၏ key များနှင့် ကိုက်ညီရမည်၊ variable များနှင့် object အတွင်းရှိ အစိတ်အပိုင်းများ၏ အစီအစဥ်သည် အရေးမကြီးပါ

Задание 1

အောက်ပါကုဒ်တွင် object ၏ အစိတ်အပိုင်းများကို သက်ဆိုင်ရာ variable များထဲသို့ ရေးထည့်ထားပါသည်-

javascriptlet options = {
  color: 'red',
  width:  400,
  height: 500,
};

let color  = options.color;
let width  = options.width;
let height = options.height;

ဤကုဒ်ကို သင်ယူထားသော သဘောတရားအရ destructuring ဖြင့် ပြန်လည်ပြင်ဆင်ပါ။