Concat() Array Method in JavaScript ?

Can we merge two arrays in one array in JavaScript???
Yes, It’s definitely possible by concat() array method.
So, Let’s start to learn what is concat() array method and how it works.

• What is Concat() Array
method ?
=> In this method two…


This content originally appeared on DEV Community and was authored by Shubham Jadhav

Can we merge two arrays in one array in JavaScript???
Yes, It's definitely possible by concat() array method.
So, Let's start to learn what is concat() array method and how it works.

• What is Concat() Array
method ?
=> In this method two or more
than two arrays merge into
a single array.
The new array serialized
according to original
arrays.

• Syntax of Concat() method
array1.concat(array2)

• Example

example 1

• Explanation :-
(1) In the above example I
simply created two
arrays and name of
arrays are 'arr1' and
'arr2' respectively.

(2) Then I stored some
values in that arrays and
values are [1,2] and
[3,4].

(3) Now I was used cancat()
method to merge both
arrays.

(4) According to above
example I wrote arr1 first
and then used concat()
method and pass as
parameter second array and
the output is [1,2,3,4].

(5) Because doing this it's
return arr1 first then
arr2. If I wrote arr2
first then concat method
used the output is
different. See below code

![example 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/otzxwn7tdcfjn8c7eeyz.jpg)

(6) Now, you can see the
output different, output
is [3,4,1,2].

• The concat() methods also take individual as arguments like below.

example 3

Happy coding....
? Stay tuned with us for more
JavaScript topics.
? Thanks for reading...


This content originally appeared on DEV Community and was authored by Shubham Jadhav


Print Share Comment Cite Upload Translate Updates
APA

Shubham Jadhav | Sciencx (2021-09-12T05:37:48+00:00) Concat() Array Method in JavaScript ?. Retrieved from https://www.scien.cx/2021/09/12/concat-array-method-in-javascript-%f0%9f%9a%80/

MLA
" » Concat() Array Method in JavaScript ?." Shubham Jadhav | Sciencx - Sunday September 12, 2021, https://www.scien.cx/2021/09/12/concat-array-method-in-javascript-%f0%9f%9a%80/
HARVARD
Shubham Jadhav | Sciencx Sunday September 12, 2021 » Concat() Array Method in JavaScript ?., viewed ,<https://www.scien.cx/2021/09/12/concat-array-method-in-javascript-%f0%9f%9a%80/>
VANCOUVER
Shubham Jadhav | Sciencx - » Concat() Array Method in JavaScript ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/12/concat-array-method-in-javascript-%f0%9f%9a%80/
CHICAGO
" » Concat() Array Method in JavaScript ?." Shubham Jadhav | Sciencx - Accessed . https://www.scien.cx/2021/09/12/concat-array-method-in-javascript-%f0%9f%9a%80/
IEEE
" » Concat() Array Method in JavaScript ?." Shubham Jadhav | Sciencx [Online]. Available: https://www.scien.cx/2021/09/12/concat-array-method-in-javascript-%f0%9f%9a%80/. [Accessed: ]
rf:citation
» Concat() Array Method in JavaScript ? | Shubham Jadhav | Sciencx | https://www.scien.cx/2021/09/12/concat-array-method-in-javascript-%f0%9f%9a%80/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.