I'm trying to find a way of creating an object where upon creation it ignores the values that are undefined.
In the example below, the variable someNames has unknown content when creating the object.
const someNames = {
catName: 'purry',
rabbitName: 'floppy',
turtleName: 'shelly'
};
const { catName, dogName, hamsterName, rabbitName } = someNames;
const animalNames = Object.assign({}, {
catName,
dogName,
hamsterName,
rabbitName
});
console.log(animalNames);// {catName: 'purry', rabbitName: 'floppy'}
What actually gets logged is this:
{
catName: 'purry',
dogName: undefined,
hamsterName: undefined,
rabbitName: 'floppy'
}