const todo = { id: 1, firstName: "David", lastName: "Mchale", age: 40, user: { isLoggedIn: false, }, }; // using curly braces means we are destructuring // NOT using curly braces and using ':' means we are just renaming const { id: position, // renaming firstName, lastName, age, user: { isLoggedIn }, // getting the value from the user isLoggedIn } = todo; console.log("destructure => ", firstName, lastName, age, isLoggedIn, position);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter