Array.prototype.concat.apply([1,2], [[3],[4]]) === [1,2,3,4]
is equal to [1,2].concat([3],[4]) === [1,2,3,4]
or in es2015 [1,2].concat(...[[3],[4]]) === [1,2,3,4]
So what you’re saying is that the concat function on arrays (i.e. Array.protype.concat ([x]) will always reduce [x] by 1 array level i.e. if arr = [1,2] it will become 1,2 and if arr = [[1,2]] it will become [1,2]).
If I understand correctly, this is a feature of the JavaScript “concat” function - i.e. this happens automatically - but only when using apply to call the function.
So, Array.prototype.concat.apply(this, [x]) === this.concat([x]), where “this” is the first argument to the concat function.
Is my understanding correct?
Interesting, I have not seen this feature in other languages.
And this is so because “apply” takes an array of arguments and treats each element of that array as a single argument.
So, an unintended consequence of “apply” is to unravel one level of the array - and this has absolutely nothing to do with the concat function which simply concatenates 2 values.
Sorry if I’m beinig overly redundant and simplistic in my understanding (still trying to learn JavaScript)