Example code for calculating duplicate values of two-dimensional arrays using Javascript and sample code for two-dimensional arrays
Preface
I encountered a problem recently. The requirement is to use Javascript to calculate the duplicate values of two-dimensional arrays. For example, there is a two-dimensional array below.
[[\ 'Error \ ', 3], [\ 'error \', 5], [\ 'error \ ', 6], [\ 'true \', 3], [\ 'true \ ', 1]
Repeated items \ 'error \ 'and \ 'true \' need to be calculated \',
Statistical Calculation Result:
[[\ 'Error \ ', 14], [\ 'true \', 4]
Implementation Code:
Var arr = [[\ 'error \ ', 3], [\ 'error \', 5], [\ 'error \ ', 6], [\ 'true \ ', 3], [\ 'true \', 1]; var obj ={}; var result = []; arr. forEach (function (arr) {obj [arr [0] = obj [arr [0]? Obj [arr [0] + arr [1]: arr [1];}); for (var I in obj) {result. push ([I, obj [I])}
Summary
The above is all about this article. I hope it will help you learn or work. If you have any questions, please leave a message.