How to merge es6 arrays
This article mainly explains "how to merge es6 arrays", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to merge es6 arrays"!
There are three methods: 1. Use "for (I in array 2) {array 1.push (array 2 [I])}" to traverse the array and add the value of one array to the end of another array; 2, use "array 1.concat (array 2...)" Statement to join multiple arrays; 3. Use "[. Array 1. Array 2]" statement.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
Es6 number combination and union method
Method 1: using for in loop
Var a = [1je 2jue 3]; var b = [4je 5je 6]; console.log (a); console.log (b); for (var i in b) {a.push (b [I]);} console.log (a)
Method 2: using concat ()
The concat () method is used to join two or more arrays.
Array1.concat (array2,array3,...,arrayX)
A new array is returned. The array is generated by adding all arrayX parameters to the arrayObject. If the argument to concat () is an array, then the elements in the array are added, not the array.
Var a = [1Jing 2jue 3]; var b = [4JJ 5J 6]; console.log (a); console.log (b); console.log (a.concat (b)); console.log (b.concat (a))
Method 3: use the extension operator "."
Var a = [1JI 2jue 3]; var b = [4JE 5J 6]; console.log (a); console.log (b); console.log ([... a dint.. b])
Thank you for your reading, the above is the content of "how to merge es6 arrays". After the study of this article, I believe you have a deeper understanding of how to merge es6 arrays, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!