Skip to content

Instantly share code, notes, and snippets.

@marksherman
Created October 25, 2019 19:49
Show Gist options
  • Save marksherman/8030a554d9b5ae38de7f4825f6daaa1b to your computer and use it in GitHub Desktop.
Save marksherman/8030a554d9b5ae38de7f4825f6daaa1b to your computer and use it in GitHub Desktop.
Finding the Largest value in an Array (javascript)
var readings = [0, 5, 9, 18, 2, 9, 5];
// find the largest value in the array 'readings'
var max = 0;
for (var i = 0; i < readings.length; i++) {
if (readings[i] > max) {
max = readings[i];
}
}
console.log('The highest reading is: ' + max);
@marksherman
Copy link
Author

You can copy this whole thing into the javascript console and it will work! Try it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment