1let arr1 = [0, 1, 2];
2let arr2 = [3, 5, 7];
3let primes = arr1.concat(arr2);
4
5// > [0, 1, 2, 3, 5, 7]
1//for ES5
2var array1 = ["Rahul", "Sachin"];
3var array2 = ["Sehwag", "Kohli"];
4
5var output = array1.concat(array2);
6console.log(output);
7
8//for ES6, we use spread operators to concat arrays
9
10var array1 = ["Dravid", "Tendulkar"];
11var array2 = ["Virendra", "Virat"];
12
13var output = [...array1, ...array2];
14console.log(output);
15
1var str1 = "Hello ";
2var str2 = "world!";
3var res = str1.concat(str2);
4console.log(res);
1
2var str1 = "Hello ";
3var str2 = "world!";
4var res = str1.concat(str2);
5// does not change the existing strings, but
6// returns a new string containing the text
7// of the joined strings.
1
2let chocholates = ['Mars', 'BarOne', 'Tex'];
3let chips = ['Doritos', 'Lays', 'Simba'];
4let sweets = ['JellyTots'];
5
6let snacks = [];
7snacks.concat(chocholates);
8// snacks will now be ['Mars', 'BarOne', 'Tex']
9// Similarly if we left the snacks array empty and used the following
10snacks.concat(chocolates, chips, sweets);
11//This would return the snacks array with all other arrays combined together
12// ['Mars', 'BarOne', 'Tex', 'Doritos', 'Lays', 'Simba', 'JellyTots']
13
1const num1 = [2, 4, 5, 3, 8, 9, 11, 33, 44];
2const num2 = [22, 33, 44, 55, 66, 77, 88];
3
4const concatNumbers = num1.concat(num2)
5console.log(concatNumbers)
6//Expected output:
7/*[
82, 4, 5, 3, 8, 9,
9 11, 33, 44, 22, 33, 44,
10 55, 66, 77, 88
11 ]
12*/