Sometimes you would like to have a destructured variable with a different name than the property name. In that case, you’ll use a : newName
to specify a name for the variable. This process is called destructuring aliases.
1 2 3 | const obj = { x: 1 }; // Grabs obj.x as as { otherName } const { x: otherName } = obj; |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.