Spread Operator Flashcards
function sum(x, y, z) { return x + y + z; }
const numbers = [1, 2, 3, 5];
console.log(sum(_________));
…numbers
function sum(x, y, z) { return x + y + z; }
const numbers = [1, 2, 3, 5];
console.log(sum(…numbers)); //
expected output: 6
only takes in x,y,z
function sum(x, y, z) { return x + y + z; }
const numbers = [1, 2, 3];
console.log(sum(…numbers)); //
expected output: 6
const numbers = [1, 2, 3];
console.log(…numbers)); //
1,2,3
numbers
const numbers = [1, 2, 3];
console.log(numbers)); //
[1,2,3]
array
let certs = [“aaa”,’bbb’,”ccc”];
let certValid = [222, 111, …certs, 333];
console.log(certValid);
[222, 111, “aaa”, “bbb”, “ccc”, 333]
let certs = [“aaa”,’bbb’,”ccc”];
let certValid = [222, 111, certs, 333];
console.log(certValid);
[222, 111, [ “aaa”, “bbb”, “ccc”], 333]
adds the array into another array as an array
function sum(x, y, z) { return x + y + z; }
const numbers = [1, 2, 3];
console. log(sum(…numbers)); // spread operator
console. log(sum(_______)); // WRITE OLD WAY
console.log(sum(numbers1[0],numbers1[1],numbers1[2]));
const numbers = [1, 2, 3]; const numbers2 = // copy array with spread
const numbers2 = […numbers];
let certs2 = […certs];
let certs = [“aaa”,’bbb’,”ccc”];
console.log(certs === certs2); // TRUE / FALSE
FALSE
OBJECTS are not the same in memory.
let array1 = [1,2,3];
let array2 = [4,5,6];
let array3 = […array1, array2];
console.log(array3);
[1, 2, 3, [4,5,6]
let array1 = [1,2,3];
let array2 = [4,5,6];
let array3 = […array1, …array2];
console.log(array3);
[1, 2, 3, 4, 5, 6];
let array1 = [1,2,3];
let array2 = [4,5,6];
// concat with method // concat with spread operator
array1.concat(array2);
let array3 = […array1, …array2];
the …spread operator does 4 things.
- //adds elements of an existing array into an new array.
- // pass elements of an array as arguments to a function
- // copy array
- // concat arrays
the _______ condenses an array
…rest