Hosting Solutions
mobile_logo Table of Contents


The concat() method is used to concatenate(combine) data. When the object calling the concat() method is an Array, an array object is returned. When the object calling the concat() method is a String, a string object is returned. The argmunets can be of mixed data types, but the returned object type will always match the calling object's type.

Syntaxobject.concat( ...arguments )


...arguments Provide zero or more comma separated object or literal values.


Calling concat() on an Array object: var arr1 = ["Apple","Orange","Banana"]; var arr2 = ["Celery","Onion"]; var arr3 = ["Chicken","Fish","Beef"]; var result = arr1.concat( arr2, arr3 ); document.write( result ); /* Apple,Orange,Banana,Celery,Onion,Chicken,Fish,Beef */ Calling concat() on a String object: var str1 = "abc"; var str2 = "def"; var str3 = "ghi"; var str4 = "jkl"; var result = str1.concat( str2, str3, str4 ); document.write( result ); /* abcdefghijkl */ Passing mixed data types into the arguments: var str = "abc"; var arr = ["Apple","Orange","Banana"]; var num = 5; var result = str.concat( arr, num ); document.write( typeof result + " | " + result ); /* string | abcApple,Orange,Banana5 */