<script> let values = [22, 9, 60, 12, 4, 56]; let max = Math.max(...values); let min = Math.min(...values); console.log(max); console.log(min); let arr1 = [1, 1, 2, 3]; let arr2 = [13, 21, 34]; let copia = [...arr1]; // a copy of arr1 is created console.log(copia); let fibArray = [0, ...arr1, 5, 8, ...arr2]; // first 10 Fibonacci numbers console.log(fibArray); let [a, b, c] = [22, 9, 60]; console.log(a); [b,c]=[c,b]; console.log(b); // ignoring values let [h, , i] = [13, 21, 34]; // h=13, i=34 // using with rest let [j, k, ...l] = [2, 3, 5, 8]; // j=2, k=3, l=[5,8] let obj = { p: 1, q: true, r: "FK" }; let { p, r } = obj; // p=1, r="FK" let { q: flag, r: name } = obj; // Renaming: flag=true, name="FK" let { q, t = "India" } = obj; // q=true; t="India" function minAndMax1(...nums) { return [Math.min(...nums), Math.max(...nums)]; } let [small1, big1] = minAndMax1(22, 9, 60, 12, 4, 56); </script>
Ejemplos de uso de spread:
https://davidwalsh.name/spread-operator
https://codeburst.io/a-simple-guide-to-destructuring-and-es6-spread-operator-e02212af5831