In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to calculate the average value of javascript two-dimensional array". In the daily operation, I believe many people have doubts about how to find the average value of javascript two-dimensional array. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to find the average value of javascript two-dimensional array". Next, please follow the editor to study!
JS two-dimensional array to calculate the average method: 1, nested double-layer for loop through all the elements of the two-dimensional array; 2, in the loop body, use the "sum+=arr1 [I] [j]" statement to add and sum all the array elements; 3, divide the sum of array elements by the number of array elements to get the average.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Average value of javascript two-dimensional array
To require the average of a two-dimensional array, we need to get each element in the two-dimensional array, add them up, and divide by the number of elements.
So how do you get every element of a two-dimensional array?
When you see this, you think of the for loop, which uses array subscripts to get elements. Because it is a two-dimensional array, two layers of for loops are used for nesting: the first layer controls the array row subscript and the second layer controls the array column subscript.
Ok, let's look at the implementation code:
Var sum=0;var Ball0; / / this variable is defined to record the total number of elements in the array var arr= [[12 beats 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23]; for (var iPersoni.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.