Javascript Concat Function

CONCAT function is used for merging two or more array or you can push value into array by using CONCAT in JavaScript.

Syntax: var1.concat(var2)

Let me show here some examples for CONCAT function.

Example 1:
var a1 = [“a”,”b”,”c”];
var a2 = [“d”,”e”,”f”];
var c = a1.concat(a2);
console.log(c); // [“a”,”b”,”c”,“d”,”e”,”f”]

Example 2:
var a1 = [1,2,3];
var a2 = [4,5,6];
var c = a1.concat(a2);
console.log(c); // [1,2,3,4,5,6]

You can also merge one or more array as same like above example let me show you one more example-

var a1 = [1,2,3];
var a2 = [4,5,6];
var a3 = [7,8,9];
var c = a1.concat(a2,a3);
console.log(c); // [1,2,3,4,5,6,7,8,9]

Example 3: Use of CONCAT function you can push single value into array
var a1 = [1,2,3];
var c = a1.concat(4,5);
console.log(c); // [1,2,3,4,5]

Example 4: Use of CONCAT function you can merge and push single value into array
var a1 = [1,2,3];
var a2 = [4,5,6];
var c = a1.concat(a2,8);
console.log(c); // [1,2,3,4,5,6,8]

News Reporter
IT Software and web development, Core PHP, JavaScript, JQuery, HTML, CSS, CakePHP, Angularjs, Codeigniter etc.

9 thoughts on “Javascript Concat Function

  1. Hello, you used to write great, but the last few posts have been kinda boring¡K I miss your great writings. Past few posts are just a little out of track! come on!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code