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?