Answers for "concat two arrays"

47

combine two arrays javascript

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

// > [0, 1, 2, 3, 5, 7]
Posted by: Guest on February-02-2020
25

merge array in js

//for ES5
var array1 = ["Rahul", "Sachin"];
var array2 = ["Sehwag", "Kohli"];

var output = array1.concat(array2);
console.log(output);

//for ES6, we use spread operators to concat arrays

var array1 = ["Dravid", "Tendulkar"];
var array2 = ["Virendra", "Virat"];

var output = [...array1, ...array2];
console.log(output);
Posted by: Guest on April-28-2020
15

javascript concat two arrays

//ES6
const array3 = [...array1, ...array2];
Posted by: Guest on July-03-2020
3

js join two arrays

[1,2,3].concat([4,5,6])
// [1,2,3,4,5,6]
Posted by: Guest on October-04-2020
0

concat two arrays

public static void main(String[] args) {

       String[] arr3 = {"A", "B", "C","Z","N"};
       String[] arr4 = {"D", "E", "F","G","U"};
ArrayList<String> list1 = new ArrayList<>();  
//  [A, B, C, Z, N, D, E, F, G, U]

       for( String each: arr3 ){
           list1.add( each );
       }
       for(String each1 : arr4  ){
           list1.add(each1);
       }
System.out.println(list1); // [A, B, C, Z, N, D, E, F, G, U]
Posted by: Guest on June-09-2021

Browse Popular Code Answers by Language