1
00:00:02,420 --> 00:00:08,300
There also is a useful method for adding elements to an array and returning a brand new array which

2
00:00:08,300 --> 00:00:12,150
again can be useful in situations where you want to create a copy of an array,

3
00:00:12,230 --> 00:00:16,450
maybe after adding new elements to it, let me show what I mean.

4
00:00:16,490 --> 00:00:22,550
I'll comment this out and instead create stored results here by using my test results

5
00:00:24,090 --> 00:00:31,470
and now here, there is the concat method which we can call. The concat method allows you to concatenate,

6
00:00:31,530 --> 00:00:36,050
so to add elements at the end of an array.

7
00:00:36,070 --> 00:00:41,760
Now therefore it's of course a bit like push, with push you can also add items to an array, by the way also

8
00:00:41,760 --> 00:00:42,960
more than one item,

9
00:00:42,960 --> 00:00:51,270
they will be added at the end but concat actually here takes an array or multiple arrays but not individual

10
00:00:51,270 --> 00:00:58,140
numbers or items in general but arrays, one or more arrays and combines these arrays with this array.

11
00:00:58,290 --> 00:01:02,330
So it does not add these arrays as new nested arrays,

12
00:01:02,340 --> 00:01:08,070
that is what would happen if you pushed an array, that would add this as a single element in the existing

13
00:01:08,070 --> 00:01:13,620
array hence creating a nested array, concat on the other hand will pull out all elements of the array

14
00:01:13,620 --> 00:01:19,320
you are passing here and add them as new elements to the existing array and it will then also return a brand

15
00:01:19,350 --> 00:01:22,230
new array. So it will create a copy of the array,

16
00:01:22,260 --> 00:01:27,780
add these items and return that copied brand new array, hence creating a new place in memory and a

17
00:01:27,780 --> 00:01:28,670
new address.

18
00:01:29,580 --> 00:01:37,410
So here for example, if we have 3.99 and 2 and I concatenate this here, what you'll see is if

19
00:01:37,410 --> 00:01:44,310
I reload, here we get the array with 3.99 and 2 at the end which are the two values I just added.

20
00:01:44,550 --> 00:01:49,580
And of course please also note that when I push 5.91 to test results,

21
00:01:49,740 --> 00:01:55,560
this does not end up in my stored result which is the first array I output here because concat returned

22
00:01:55,560 --> 00:02:02,130
a brand new array. So you see no 5.91 here in the first array, only in the second one.

23
00:02:02,130 --> 00:02:07,860
So that's also useful, concat can be really useful if you have array data and you want to combine it

24
00:02:07,860 --> 00:02:13,260
with an existing array and the fact that you get a brand new array is also quite convenient because

25
00:02:13,260 --> 00:02:19,740
that often avoids problems where you manipulate an existing array when you actually didn't want to

26
00:02:19,740 --> 00:02:20,310
do that.
