Skip to content

Instantly share code, notes, and snippets.

@martingaido
Created August 7, 2020 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martingaido/45f2238d02e04878b9e0fd22f6177deb to your computer and use it in GitHub Desktop.
Save martingaido/45f2238d02e04878b9e0fd22f6177deb to your computer and use it in GitHub Desktop.
Spread Operator in JavaScript
/* 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