Skip to content

Instantly share code, notes, and snippets.

@jleonelpm
Created January 6, 2023 13:36
Show Gist options
  • Save jleonelpm/ada37b8eb8b52f738903a7a66fdbc15e to your computer and use it in GitHub Desktop.
Save jleonelpm/ada37b8eb8b52f738903a7a66fdbc15e to your computer and use it in GitHub Desktop.
Ejemplo del operador Spread en Javascript
//Ejemplo 1
function suma(x, y, z) {
return x + y + z;
}
const numeros = [9,10,11];
console.log(suma(...numeros));
//Ejemplo 2
const fruits = ['watermelon', 'mango', 'lemon'];
const food = ['meat', ...fruits, 'milk', 'cheese'];
console.log(food);
//meat, watermelon, mango, lemon, milk, cheese
//Ejemplo 3
const profile = {
firstName: 'Mike',
lastName: 'Smith',
};
const direccion = {
country: 'Estados Unidos',
city: 'New York',
};
const user = {
...profile,
gender: 'male',
...address,
};
console.log(user)
/* The output will be
{
firstName: 'Mike',
lastName: 'Smith',
gender: 'male',
country: 'Estados Unidos',
city: 'New York'
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment