Always know that JS array built-in object has a concat method, but did not do much research, today by chance to look at
concat is connecting one or more arrays
Returns a copy of the array after the connection
var oldarr=[];
var arr=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]];
var newarr=oldarr.conat (arr);
Console.log (NEWARR);
Console.log (Oldarr); //[] did not change
So I thought I would connect each item of the array to the Oldarr as an array.
This requires the Apply method to change the array to parameter list arguments
Console.log (Array.prototype.concat.apply (Array,arr));
It turned out strange.
No results were thought of.
What the hell is the arrow place???
Think about it.
Array.prototype.concat.apply (Array,arr);
Not that the array called the concat on Array.prototype and then passed in the parameter arr
Changing the array to number String is not the way to borrow the Concat method on Array.prototype.
Then add the caller to the 0-bit position of the array
I feel that it is arr.unshift (Array);
Anything else, it's going to push.
Let's see the picture below.
Console.log (Array.prototype.concat.apply (Number,arr));
Console.log (Array.prototype.concat.apply (String,arr));
Console.log (Array.prototype.concat.apply (Regexp,arr));
that's what it looks like.
So change the parameters inside the aplly to []
Console.log (Array.prototype.concat.apply ([],arr));
You can simply write [].concat.apply ([],arr);
Arrays can not only concatenate array arrays but also concatenate string numeric objects, etc.
Console.log ([].concat ({a:2,b:3,c:3}));
He's going to put the object in the array, and there's no connection. I have you .
Console.log ([].concat ("123"}));
According to these I have summed up if the concat passed in the parameter is not an array will not traverse direct violence added to the array item
When the argument is an array, it traverses the
Need to pay attention to is not silly to use String.Concat (); Number.concat (), etc.
Above is to use the Apply method to change this point to the borrowed
It's not concat itself.
String.prototype there are concat but the results are not the same drop!
It's just my personal understanding that I want to help you.
Array,prototype.concat.apply and [].conat.apply.