javascript
Find the nth largest element in a sorted array
let arr = [25, 78, 54, 98, 23, 54, 11, 2]
arr.sort((a, b) => a - b);
console.log(arr, 'array')
const nthLargest = arr[arr.length - 1];
console.log(nthLargest, 'output');
Output
98
Was this helpful?
Similar Posts
- Javascript Code for Sorting array and finding Largest No. in Array
- Array.find() - get the very first element satisfy a condition Javascript
- Get the largest value from an array using javascript
- Javascript to find which DOM element has the focus
- Find the shortest string in array
- Find the minimum value from an array javascript
- Find the maximum value from an array using Javascript