Object and Array Destructuring
Tue Apr 22 2025 19:51:37 GMT+0000 (Coordinated Universal Time)
Saved by
@signup
// 🌟 Object Destructuring
const student = {
name: "Rahul",
roll: 101,
class: "10th"
};
const { name, roll } = student;
console.log("Name:", name); // Rahul
console.log("Roll No:", roll); // 101
// 🌈 Array Destructuring
const fruits = ["apple", "banana", "mango"];
const [fruit1, fruit2] = fruits;
console.log("First Fruit:", fruit1); // apple
console.log("Second Fruit:", fruit2); // banana
content_copyCOPY
Comments