JavaScript හි වස්තු deconstructuring විචල්ය නම්
විචල්ය නම් වස්තු යතුරු නම් වලට නොගැලපෙන පරිදි කළ හැකිය:
let obj = {
year: 2025,
month: 12,
day: 31,
};
let {year: y, month: m, day: d} = obj;
console.log(y); // 2025 ප්රතිදානය කරයි
console.log(m); // 12 ප්රතිදානය කරයි
console.log(d); // 31 ප්රතිදානය කරයි
පහත කේතයේ, වස්තුවේ කොටස් අදාළ විචල්යයන්ට ලියා ඇත:
let options = {
color: 'red',
width: 400,
height: 500,
};
let c = options.color;
let w = options.width;
let h = options.height;
මෙම කේතය ඉගෙන ගත් න්යායට අනුව deconstructuring හරහා නැවත සකස් කරන්න.