Javascript Concat() Method to Join or Concatenate Multiple Arrays Together into One Full Example
Jan 9, 2025
Buy the full source code of application here:
Show More Show Less View Video Transcript
0:00
uh hello guys in this video we will look
0:02
at another JavaScript array method which
0:05
is used for concatenating two or
0:07
multiple arrays together into a single
0:09
array so this method is called as concat
0:13
c n c
0:15
a so concat method this is actual method
0:20
and what it does this method do so let's
0:22
suppose I
0:23
declare
0:26
uh some arrays here so this is numerical
0:30
values it can even be string values as
0:33
well let me also have
0:41
names so we have these two arrays we
0:43
have declared this is the first array
0:45
which is a numerical array the second
0:47
one is a string array which contains
0:50
three elements so now if you want to
0:52
join these two arrays together into a
0:53
single output array you use that concat
0:57
method so what you will simply say you
0:59
will declare the third variable which
1:01
will I will call this as result and you
1:04
you invoke this on the first array that
1:07
you're concatenating so you will simply
1:09
say the name of the array num one and
1:12
then there is this method which is
1:14
concat so in the drop down if you see
1:17
concat is showing up
1:20
concat and then in the argument you need
1:23
to pass the second array to which you
1:25
need to join or concatenate the array
1:29
this is a second secondary name you need
1:31
to replace here in the
1:33
argument simply and if you just console
1:37
log it the actual result which is
1:40
coming so now if you see in this result
1:44
we got eight
1:46
elements so the first array contained uh
1:49
1 2 3 4 5 and the second array contained
1:53
three elements so 5 + 3 comes out to be
1:56
eight elements so if you see the result
1:58
we have exactly eight elements
2:01
there so it has concatenated both the
2:04
arrays together into a single output
2:07
array so it contains eight
2:10
elements so 0 to
2:14
7 so the actual uses of this concat
2:17
method it doesn't modify the any
2:20
existing array it just joins the actual
2:23
content so whatever content present in
2:26
the first array and the second array
2:27
simply joins it into a single output
2:30
array you can even have three arrays as
2:33
well let's suppose I have another
2:36
array num two and I have this area as
2:40
well let's
2:44
suppose so I have these three arrays so
2:46
what we can do if you want to modify
2:49
this if you want to concatenate all
2:50
these three arrays into a single
2:54
array so what you will do you will
2:56
simply say
2:58
result and then you will simply
3:01
say the first array and then Conca and
3:05
here you need to pass two arguments
3:08
instead of one so you will pass both
3:10
these arrays as arguments so you will
3:12
simply say num two and then the
3:16
names so now if you see total elements
3:20
are returned to be 12 so it basically
3:24
concatenated these five elements then
3:27
these four elements nine plus three so
3:30
total 12 elements are there so if you
3:33
see the output exactly we have 12
3:37
elements so it has
3:39
concatenated all the three arrays
3:42
together so in this way you can have as
3:44
many arrays as you want let's suppose I
3:47
declare it one more array I call this
3:50
num
3:53
three I change the values
4:06
so what do you need to do uh you need to
4:08
Simply add one more argument right here
4:11
simply say num
4:13
three so now you'll see we have 16
4:16
elements so it totally depends upon you
4:18
how many arrays you are concatenating so
4:20
in this case we are
4:22
concatenating four arrays so on the
4:26
first array you actually invoke the
4:27
method so num one con cat and then
4:31
remaining three we actually pass it as
4:33
an argument so it totally depends upon
4:36
you how many array you are concatenating
4:38
it so depending upon that you will be
4:41
sending it in the argument so in this
4:44
way you can concatenate as many arrays
4:46
together into a single array using this
4:49
concat method and it doesn't modify the
4:52
content of the array and if you
4:55
have let's suppose some elements are
4:58
repeating
5:01
so so this Smith is repeating let's
5:05
suppose in this names AR you see Smith
5:08
is appearing duplicate number of times
5:10
it is appearing two times so in the
5:13
output array you will see Smith
5:14
appearing duplicate number of times so
5:16
it doesn't modify the content of the
5:18
array it doesn't remove the elements
5:20
which are repeating it so concat just
5:23
joins the actual elements together into
5:25
an output
5:27
array so you can concat join multiple
5:30
arrays together using this concat array
5:34
function so this was that video about so
5:38
do check out my free mediat tools.com
5:41
website as well which
5:43
contains open source tools about audio
5:46
video and image as well and uh please
5:49
hit that like button subscribe the
5:50
channel and I will be seeing you in the
5:52
next video
#Programming
#Software
#Scripting Languages
