What are the methods of merging arrays with JavaScript
JavaScript merging array methods, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
1. The reduce method starts with the first item in the array and traverses it one by one to the end. ReduceRight starts with the last item in the array and traverses the first item forward.
2. Receive two parameters: a function called in each project and the initial value that serves as the basis for the merge.
The functions passed to reduce () and reduceRight () take four parameters: the previous value, the current value, the item index, and the array object.
Example
Var values = [1Jing 2, index, array) {return prev + cur;}); var sum = values.reduce (function (prev, cur, index, array) {return prev + cur;}); alert (sum); / / 15 var values = [1 dagger, 2, index, array); var sum = values.reduceRight (prev, cur, index, array) {return prev + cur;}); alert (sum); / / 15
Avascript
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.