I want to pass only a part of array into another array through spread operator.
I tried passing an entire array into another array with spread operator.It worked.
<code>let array1 = [1,2,3,4,5];
let array2 = [...array1, 6,7,8];
console.log(array2);
</code>
<code>let array1 = [1,2,3,4,5];
let array2 = [...array1, 6,7,8];
console.log(array2);
</code>
let array1 = [1,2,3,4,5];
let array2 = [...array1, 6,7,8];
console.log(array2);
I expect to pass only first 3 elements of array [1,2,3] through spread operator into another array. How to do that?
New contributor
Fred is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.