February 2019
Beginner
694 pages
18h 4m
English
Interestingly enough, the rest and spread syntax can also be used with arrays. Consider the following code:
let firstArray = [1, 2, 3, 4, 5];
console.log(`firstArray=${firstArray}`);
firstArray = [...firstArray, 6, 7, 8];
console.log(`firstArray=${firstArray}`);
Here, we have defined an array name firstArray that has five elements, which are the numbers 1 through 5. We are then logging this array to the console. Note the next line of this code snippet, where we are using the rest syntax to append the values 6, 7, and 8 to the existing array. We are then logging the firstArray array to the console. The output of this code is as follows:
firstArray=1,2,3,4,5 firstArray=1,2,3,4,5,6,7,8
As we can see, the values ...
Read now
Unlock full access