Already talked about hidden elements to their Ray and why push is not always the best approach.
But you might also have a similar question.
For example, here we have a task right to function which will concatenate two arrays.
And actually, you might use here put and it will be an answer.
This is where here you can actually write a function merge arrays.
And here we get into a race, for example, array one and array two.
And here you might write array one bush.
And here you spread.
Offer a tool.
And after this, you can just return array one.
And actually, not a lot of people will write code like this because here you are using input and then
US president as a tool.
But you might think about such approach now to see the problem, we must create, first of all, our
result.
And here, inside the result, we need to use two arrays array one, for example, it will be just one,
and our array to here will be, for example, two and three and no one to call our merchandise.
And Parsons said, first of all, array one and secondly, array two.
And let's check in console.log what we're getting.
So first of all, result.
Then there's a one and there's a tool aimed at loading the page and we're getting one two three one
two three two three.
This is exactly the problem.
Like it wasn't previous VIDEO Bush mutates array.
This is way here where change in array one, even if we don't want to change it.
This is why push in this case is not the best approach.
What we can use here instead is, say, the array conquered, which is all the approach of JavaScript
or just to spread operated just like we did previously.
So instead of this return and the report, we can write here, first of all, already one dot com cat
and we have concatenate function on their right.
And here we're spreading our array to.
Let's check the software to load in the page.
Here is our result one, two three.
And here are two one one and three two two three.
And this is exactly the correct approach because concatenate does not mutate and rape.
In this case, it will return for us in array.
This is why everything is fine.
If you don't want to use the ray, come cut.
You can always just use a spread operator.
So here we will use array one as a spread.
And here we are spreading as a tool and actually the result will be exactly the same.
We're getting one two three.
And actually, I really like this approach because it is more flexible and you can merge not only arrays
but also objects.
You can add new elements here, and it is more modern if you, for example, have a question to concatenate
three arrays or more.
It is also possible, actually, even array can cat kind of work with several arrays, as you can see
here inside documentation.
Here we have three different arrays and you can write first array dot com cat and then you have secondary
and third rate.
And actually, it will work correctly, but actually you can do exactly the same with spread.
Here you are, spreading at a one, then array two and here Array three if you need two.
So both variants are possible.