concat creates a new array containing the elements of the objects that are called. If the array is a sequence, the array adds its elements and the value itself.
var newArray = newArray.concat(value1[, value2[, ...[, valueA]]])
The arguments of this function are arrays or values that must be added to the given array. The number of arguments for this function depends on the number of arrays or values to be combined.
NOT: Combining array / values does not change the originals. Also, any operation on the new array does not affect the original arrays.
var list1 = ["j","a","v","a"],
list2= ["s","c","r","i","p","t"];
console.log(list1.concat(list2));
output:
[“j”, “a”, “v”, “a”, “s”, “c”, “r”, “i”, “p”, “t”]
Number or text doesn’t matter.
var num = [1,2,3,4],
txt = ["true","codes",".org"];
console.log(num.concat(txt));
output:
[1, 2, 3, 4, “true”, “codes”, “.org”]
The number of arrays does not notice.
var list1 = [1, 2, 3],
list2 = ["a","b","c"],
list3 = [undefined];
console.log( list1.concat( list2 , list3 ))
output:
[1, 2, 3, “a”, “b”, “c”, undefined]
We can define the array in ‘concat’.
var list = [1, 2, 3, 4];
console.log( list.concat(["true","codes"],[5,6,7]))
output:
[1, 2, 3, 4, “true”, “codes”, 5, 6, 7]