Program to use JavaScript Spread (…)Operator
let a = [1,2,3,4,5];
let b = [6,7,8];
let c = [...a,...b]
console.log(c);
Output
[
1, 2, 3, 4,
5, 6, 7, 8
]
Steps Description
- Declare three variables
a, b
andc
- Initialize three variables with array value respectively
a = [1,2,3,4,5], b = [6,7,8]
andc = [...a,...b]
- The spread(...) operator converts multiple arrays into a single array.
- The value of
c
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Spread (...)Operator
let d = [1,2,3,4,5];
let e = [6,7,8];
let f = [9,10];
let g = [...d,...e,...f];
console.log(g);
Output
[
1, 2, 3, 4, 5,
6, 7, 8, 9, 10
]
Steps Description
- Declare Four variables
d, e, f
andg
- Initialize Four variables with array value respectively
d = [1,2,3,4,5], e = [6,7,8], f = [9,10]
andg = [...d,...e,...f]
- The spread(...) operator converts multiple arrays into a single array.
- The value of
g
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Spread (...)Operator
let h = ['Apple', 'Mango', 'Banana'];
let i = ['Orange', 'Pomegranate'];
let j = [...h,...i];
console.log(j);
Output
[ 'Apple', 'Mango', 'Banana', 'Orange', 'Pomegranate' ]
Steps Description
- Declare three variables
h, i
andj
- Initialize three variables with array value respectively
h = ['Apple', 'Mango', 'Banana'], i = ['Orange', 'Pomegranate']
andj = [...h,...i]
- The spread(...) operator converts multiple arrays into a single array.
- The value of
j
variable is displayed with the help of console.log inbuilt function