
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Highest and lowest value difference of array JavaScript
We are required to write a JavaScript function that takes in an array of numbers. The function should pick the greatest and lowest value from the array and return their difference.
Example
const arr = [4, 6, 3, 1, 5, 8, 9, 3, 4]; const difference = (arr = []) => { const highest = Math.max(...arr); const lowest = Math.min(...arr); return highest - lowest; }; console.log(difference(arr));
Output
And the output in the console will be −
8
- Related Articles
- Highest and lowest in an array JavaScript
- MySQL order by from highest to lowest value?
- Java Program to get the lowest and highest value in TreeSet
- Returning the highest value from an array in JavaScript
- JavaScript Array showing the index of the lowest number
- Program to find out the minimum cost path between the lowest value vertex to the highest value vertex (Python)
- How to find inside an array of objects the object that holds the highest value in JavaScript?
- Pair of (adjacent) elements of an array whose sum is lowest JavaScript
- A single MySQL query to find the highest and lowest among two tables?
- Get row data for the lowest and highest values in a MySQL column
- The maximum and minimum temperature displayed daily in the weather bulletin refers to the(a) Highest day temperature and lowest night temperature of the day(b) Highest temperature and highest temperature of the month(c) Temperature recorded at 12 noon and at midnight 900.00h)(d) Average highest temperature of the day and average lowest temperature of night
- Returning the highest number from object properties value – JavaScript
- JavaScript: Combine highest key values of multiple arrays into a single array
- Highest occurrence in an array or first selected in JavaScript
- Figuring out the highest value through a for in loop - JavaScript

Advertisements