Home >Web Front-end >JS Tutorial >How to sum jquery array elements
Method for summing jquery array elements: 1. Use for loop and length attribute to traverse the array, the syntax is "for(i=0;i
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.
Method of summing jquery array elements
1. Create a new html file, named test.html, to explain how jquery sums The sum of the element values in an array.
In the js tag, create an array and initialize a variable to retain the sum value. Use a for loop to traverse the array, where the length property is used to get the length of the array. Use the "=" operator to accumulate array element values.
#2. In the js tag, use the write() method to output the calculated result.
Open the test.html file in the browser to view the results.
Summary:
1. Create an array and initialize a variable to retain the sum value.
2. Use a for loop to traverse the array, where the length attribute is used to obtain the length of the array.
3. Within the for loop, use the "=" operator to accumulate the array element values.
4. In the js tag, use the write() method to output the calculated results.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of How to sum jquery array elements. For more information, please follow other related articles on the PHP Chinese website!