JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Useful Array Methods

Vic Mercier
Vic Mercier
3,276 Points

concat

If I understand this method well, the concat method will add something at the END of an another array?

2 Answers

Steven Parker
Steven Parker
176,602 Points

You have the basic idea.

But it does not modify the array directly. Instead, it returns a new array composed of the others joined together.

Check the MDN page for more information.

Steven Parker
Steven Parker
176,602 Points

My answer is about Array.prototype.concat(), which I believe is the topic of Vic's question.

ian izaguirre
ian izaguirre
3,220 Points

It would be incorrect to say that concat will add "something" at the end of an Array. I think thats why Trent that commented above was confused, since you used the word "something".

The difference between Push and Concat would be that concat deals with arrays. Concat merges two or more arrays while also not changing the original array and rather just returns a new array as the result.

... If we had an example that had an array with only one value and you wanted to add it to another array, then what would be another difference between using Concat vs Push? That would be that Push would change the original array and return the length of the array.

Steven Parker
Steven Parker
176,602 Points

For some students, English is as much of a challenge as the technology. I try to give some leeway on the language and do my best to "interpret" the underlying quesiton.