Created
January 6, 2023 13:36
-
-
Save jleonelpm/ada37b8eb8b52f738903a7a66fdbc15e to your computer and use it in GitHub Desktop.
Ejemplo del operador Spread en Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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