---
title: "Discussion on \"Find the second largest number in a array\" | Hashnode"
description: "Discussion on \"Find the second largest number in a array\". function findSecondLargest(arr) {\n  // Sort the array in descending order\n  arr.sort(function(a, b) {\n    return b - a;\n  });\n\n  // Return the element at index 1 (the second largest)\n  return arr[1];\n}\n\n// Example usage\nconst numbers = [10, 5, 8, 20,..."
url: "https://hashnode.com/posts/find-the-second-largest-number-in-a-array/65092f9f83cfc2d7e22db67e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Find the second largest number in a array](https://harikrishna.hashnode.dev/find-the-second-largest-number-in-a-array?utm_source=hashnode&utm_medium=feed)

function findSecondLargest(arr) { // Sort the array in descending order arr.sort(function(a, b) { return b - a; }); // Return the element at index 1 (the second largest) return arr\[1\]; } // Example usage const numbers = \[10, 5, 8, 20,...

Sep 19, 2023 · 1 min read · harikrishna.hashnode.dev  
Read the article

-   [#array](https://hashnode.com/tag/array)
-   [#sort](https://hashnode.com/tag/sort)
-   [#2nd-largest](https://hashnode.com/tag/2nd-largest)

## Written by

[Hari Krishna Anem](https://hashnode.com/@hkrishna)

@hkrishna · Hyderabad, India

  
[View profile](https://hashnode.com/@hkrishna)

Full stack developer

Full stack developer (ReactJS, NodeJS, JavaScript, PHP, SQL)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
