Home > Web Front-end > JS Tutorial > Sample code for finding the maximum value in an array in javascript_javascript skills

Sample code for finding the maximum value in an array in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 17:08:30
Original
1192 people have browsed it
Copy code The code is as follows:



< ;title>Get the maximum value of the array

<script> <br>//Define the array<br>var arr = [1,4,3,9,5,0, -1,7,22]; <br><br>//The subscript of the maximum value is first assumed to be the subscript of the first element <br>var index = 0; <br>for(var x = 0; x < arr.length; x ){ <br><br>if(arr[index] < arr[x]){ <BR>index = x; <BR>} <BR>} <br><br>document.write("The index is the "arr[index] "maximum" in " index "); <br><br></script>








Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template