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 97 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,635
- 3
- 23
- 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,488
- 6
- 29
- 43
0
That clones the array and returns the reference to the new array.
So when you call getItems
function and manipulating its return, that won't affect the original cloned array
for more refer to this Answer:

Glorfindel
- 21,988
- 13
- 81
- 109

solimanware
- 2,952
- 4
- 20
- 40