Our goal
Let's say we want to create a new object inheriting only a few property:value from another, but not all. Just like the following:
What'...
For further actions, you may consider blocking this person and/or reporting abuse
You could also write
Excellent solution: i love the spread syntax. But i think in this case it's gonna work only for a few and well known properties to exclude from the wanted output (luca). What if the original object has hundreds of them?
Anyways, there are plenty of solutions to this problem. One for all, if you'd like to rely on some dependency: lodash.
Does
lastName
value get assigned toconst _
? I take it the_
is a convention for unused variables, seen it used before for arguments that are not referenced (I think)Yup, it's mostly an unwritten rule adopted as a convention for variables that must be there but aren't going to be referenced anywhere. Similarly if you want to use
.map()
but only need the index, not the element itself for some weird reason:It there some catch using this and not Object.assign().