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 array1 = ["Vijendra", "Singh"];
2var array2 = ["Singh", "Shakya"];
3
4console.log(array1.concat(array2));
5// output: ["Vijendra", "Singh", "Singh", "Shakya"]
1var array = ["Joe", "Kevin", "Peter"];
2array.join(); // "Joe,Kevin,Peter"
3array.join("-"); // "Joe-Kevin-Peter"
4array.join(""); // "JoeKevinPeter"
5array.join(". "); // "Joe. Kevin. Peter"
1//turns array to string
2
3const elements = ['Fire', 'Air', 'Water'];
4
5console.log(elements.join());
6// expected output: "Fire,Air,Water"
7
8console.log(elements.join(''));
9// expected output: "FireAirWater"
10
11console.log(elements.join('-'));
12// expected output: "Fire-Air-Water"
13
1const letters = ['a', 'b', 'c'];
2const numbers = [1, 2, 3];
3
4const newArray = letters.concat(numbers);
5// newArrat is ['a', 'b', 'c', 1, 2, 3]