Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:08:30
Original
1159 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:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template