How to join (merge) two arrays in JavaScript

3 Answers

0 votes
const arr1 = ["javascript", "php", "c++", "python"];
const arr2 = ["css", "html"];
  
const merged = [...arr1, ...arr2]
  
console.log(merged);
  
   
   
   
/*
run:
         
["javascript", "php", "c++", "python", "css", "html"]
       
*/

 

 



answered Nov 4, 2019 by avibootz
edited Jul 20, 2023 by avibootz
0 votes
const arr1 = ["javascript", "php", "c++", "python"];
const arr2 = ["css", "html"];
  
const merged = arr1.concat(arr2)
  
console.log(merged);
  
   
   
   
/*
run:
         
["javascript", "php", "c++", "python", "css", "html"]
       
*/

 



answered Nov 4, 2019 by avibootz
edited Jul 20, 2023 by avibootz
0 votes
const arr1 = [1, 3, 5, 9];
const arr2 = [2, 4, 6];
 
const merged = [ ...arr1, ...arr2 ];
 
console.log(merged);
 
 
 
 
 
/*
run:
 
[1, 3, 5, 9, 2, 4, 6]
 
*/

 



answered Jul 20, 2023 by avibootz

Related questions

2 answers 209 views
2 answers 204 views
3 answers 448 views
1 answer 156 views
2 answers 200 views
200 views asked Jun 9, 2015 by avibootz
1 answer 193 views
...