0
Q:

js combine arrays

let arr1 = [0, 1, 2];
let arr2 = [3, 5, 7];
let primes = arr1.concat(arr2);

// > [0, 1, 2, 3, 5, 7]
21

var hege = ["Cecilie", "Lone"];

var stale = ["Emil", "Tobias", "Linus"];

var children = hege.concat(stale);
 
3
const array1 = ["Vijendra","Singh"];
const array2 = ["Singh", "Shakya"];
const array3 = [...array1, ...array2];
3
const letters = ['a', 'b', 'c'];
const numbers = [1, 2, 3];

letters.concat(numbers);
// result in ['a', 'b', 'c', 1, 2, 3]
1
//ES6 using the spread operator
const itemsA = [ 'Lightsaber', 'Mockingjay pin', 'Box of chocolates' ];
const itemsB = [ 'Ghost trap', 'The One Ring', 'DeLorean' ]
const allItems = [ ...itemsA, ...itemsB ];
0

New to Communities?

Join the community