Created
August 7, 2020 16:33
-
-
Save martingaido/45f2238d02e04878b9e0fd22f6177deb to your computer and use it in GitHub Desktop.
Spread Operator in 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
/* Spread Operator */ | |
// Case 1 | |
const temperatures = [25, 22, 10, 34, 28, 15]; | |
console.log('Min Value: ', Math.min(...temperatures)); | |
console.log('Max Value: ', Math.max(...temperatures)); | |
// Case 2 | |
const someNumbers = ['First Name', 'Last Name', 'Age', 'Gender']; | |
const [first, ...tail] = someNumbers; | |
console.log('First Value: ', first); | |
console.log('Rest of the Array: ', tail); | |
// Case 3 | |
const group1 = ['Person1', 'Person 2', 'Person 3']; | |
const group2 = ['Person4', 'Person 5', 'Person 6']; | |
const allGroups = [...group1, ...group2]; | |
console.log(allGroups); | |
// Case 4 | |
const colors1 = { a: 'Red', b: 'Green', c: 'Blue' }; | |
const colors2 = { d: 'Yellow', e: 'Orange', f: 'Grey' }; | |
const allColors = {...colors1, ...colors2}; | |
console.log(allColors); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment