Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created September 22, 2019 16:57
Show Gist options
  • Save NyaGarcia/d1fbf34a251cfd5466f9b5a27f781576 to your computer and use it in GitHub Desktop.
Save NyaGarcia/d1fbf34a251cfd5466f9b5a27f781576 to your computer and use it in GitHub Desktop.
Adding properties conditionally with spread operator
const pokemon = {
name: 'Squirtle',
type: 'Water'
};
const abilities = ['Torrent', 'Rain dish'];
const fullPokemon = {
...pokemon,
...(abilities && { abilities })
};
console.log(fullPokemon);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment