JS Array Concatenation

concat() method joins multiple arrays, and return the combined array.

var arr1 = [4,2,8];
var arr2 = new Array(5,3,3);
var arr3 = [100,500];
var newarr = arr1.concat(arr2,arr3);
//newarr is [4,2,8,5,3,3,100,500]

The parameters can be values. In this case, the values will be added to the array.

var arr1 = [4,2,8];
var newarr = arr1.concat(5,3);
//newarr is [4,2,8,5,3]

join() method joins all elements into a string:

var arr = new Array("e","n","d","memo");
var s = arr.join(); //s is "endmemo"

endmemo.com © 2024  | Terms of Use | Privacy | Home