javascript / beginner
Snippet
Extracting Data with Object Destructuring
Destructuring is a clean way to extract properties from an object and assign them to individual variables in a single line of code.
snippet.js
1
2
3
4
const user = { name: 'Alex', role: 'Admin' };const { name, role } = user;console.log(name); // 'Alex'
nextjs
Breakdown
1
const { name, role } = user;
Extracts the 'name' and 'role' properties from the user object into separate variables.