Javascript examples for Array Operation:Array Element
Return the index of largest sum within array
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w w w .jav a 2 s .c o m*/ var largestValue =0; var locationOfLargest =0; sumArray = [1231231, 100, 909, 8, 998, 9238] for(var i = 0; i<sumArray.length; i++) { if (!largestValue || sumArray[ i ] > largestValue) { largestValue = sumArray[ i ]; locationOfLargest = i; } } console.log(locationOfLargest, largestValue); } </script> </head> <body> </body> </html>