trying to find out if there is a a way to assign certain properties from a destructured object to a new variable. I do not see anything in the specs that would be useful, any ideas?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
First, assume I have the following constant imported to my file
export const SANDWICHES = {
MEAT_BALL: 'meatball',
BLT: 'bacon lettuce tomato',
CHEESE_STEAK: 'cheesesteak',
HAM_CHEESE: 'ham and cheese',
SLOPPY_JOE: 'sloppy joe',
VEGGIE_BURGER: 'veggie'};`
import const { SANDWICHES } from './constants';
In order for me to pick out the sandwiches that I want to eat, I destructure SANDWICHES and then put them into a new variable sandwichesIWantToEat.
const { CHEESE_STEAK, SLOPPY_JOE } = SANDWICHES;
const sandwichesIWantToEat = { CHEESE_STEAK, SLOPPY_JOE };
Is there any way to destructure, and reassign to a variable in a single expression?
const {
CHEESE_STEAK,
SLOPPY_JOE
}: sandwichesIWantToEat = SANDWICHES;
Or maybe something like this?
const sandwichesIWantToEat = {
CHEESE_STEAK,
SLOPPY_JOE,
...SANDWICHES
};