what does items = [].concat(this.items) do? Looking at some JavaScript code explaining Model-View-Controller (MVC) in JavaScript but am confused as to the purpose of this concat statement. What does it achieve?
Asked
Active
Viewed 80 times
0
Werner
- 33
- 6
-
Possible duplicate of [Concat in an empty array in Javascript](https://stackoverflow.com/questions/37477483/concat-in-an-empty-array-in-javascript) – Raymond Chen Aug 06 '17 at 02:19
-
You should probably edit this question to include the relevant function from the article. Makes it easier to see in context. – Josiah Keller Aug 06 '17 at 02:28
3 Answers
1
In this case, it's there to clone the array rather than returning a reference.
Josiah Keller
- 3,587
- 3
- 25
- 35
0
Creates an empty array, and concatenates the values in the this.items array, it also creates its own copy so any changes you make to items will not be reflected in this.items
Erick
- 2,408
- 6
- 27
- 42