Skip to content

Instantly share code, notes, and snippets.

@jgwill
Last active December 4, 2018 19:24
Show Gist options
  • Save jgwill/8d27285f1f6eec0c9f4d4af40d7cd324 to your computer and use it in GitHub Desktop.
Save jgwill/8d27285f1f6eec0c9f4d4af40d7cd324 to your computer and use it in GitHub Desktop.
@stcgoal Can we Destruct JavaScript object only using prop name?
var o = new Object();
o.name = "myname in object";
o.note = "a value we wont care about";
o.description = "my description";
var { description, name } = o; // Trying to destruct only with prop name to see if that can be done (It would be implied too :) )
try {
console.log("Destruct description value : " + description);
console.log("Destruct name value : " + name);
} catch (err) {
console.log(err);
}
//@s SUccesss, you can destruct var {description,name} = o;
@eweader
Copy link

eweader commented Dec 4, 2018

Handy :)
making that very light 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment