June 5, 2023
Program to use JavaScript Array concat() method
let a = ['Cat', 'Dog'];
let b = ['Tiger', 'Lion', 'Elephant'];
let c = a.concat(b);
console.log(c);
Output
[ 'Cat', 'Dog', 'Tiger', 'Lion', 'Elephant' ]
Steps Description
- Declare three variables
a, b
andc
- Initialize three variables with array value respectively
a = ['Cat', 'Dog'], b = ['Tiger', 'Lion', 'Elephant']
andc = a.concat(b)
- In
Concat() array
method, an array can be concatenated to more than one array. - The value of
c
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array concat() method
let d = ['Peas', 'Carrot', 'Potato'];
let e = ['Tomato', 'Brinjal', 'Cabbage'];
let f = ['Green Chilli', 'Green Coriander']
let g = d.concat(e,f);
console.log(g);
Output
[
'Peas',
'Carrot',
'Potato',
'Tomato',
'Brinjal',
'Cabbage',
'Green Chilli',
'Green Coriander'
]
Steps Description
- Declare four variables
d, e, f
andg
- Initialize four variables with array value respectively
d = ['Peas', 'Carrot', 'Potato'], e = ['Tomato', 'Brinjal', 'Cabbage'], f = ['Green Chilli', 'Green Coriander']
andg = d.concat(e,f)
- In
Concat() array
method, an array can be concatenated to more than one array. - The value of
g
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array concat() method
let h = [1,2,3];
let i = [4,5];
let j = [6,7,8];
let k = [9,10];
let l = h.concat(i,j,k);
console.log(l);
Output
[
1, 2, 3, 4, 5,
6, 7, 8, 9, 10
]
Steps Description
- Declare five variables
h, i, j, k
andl
- Initialize five variables with array value respectively
h = [1,2,3], i = [4,5], j = [6,7,8], k = [9,10]
andl = h.concat(i,j,k)
- In
Concat() array
method, an array can be concatenated to more than one array. - The value of
l
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript Array concat() method 2 array string example 1 array number example