
- 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
Third smallest number in an array using JavaScript
Problem
We are required to write a JavaScript function that takes in an array of numbers of length at least three.
Our function should simply return the third smallest number from the array.
Example
Following is the code −
const arr = [6, 7, 3, 8, 2, 9, 4, 5]; const thirdSmallest = () => { const copy = arr.slice(); for(let i = 0; i < 2; i++){ const minIndex = copy.indexOf(Math.min(...copy)); copy.splice(minIndex, 1); }; return Math.min(...copy); }; console.log(thirdSmallest(arr));
Output
4
- Related Articles
- JavaScript Finding the third maximum number in an array
- Finding the third maximum number within an array in JavaScript
- Remove smallest number in Array JavaScript
- Finding smallest number using recursion in JavaScript
- Finding the largest and smallest number in an unsorted array of integers in JavaScript
- Get the smallest array from an array of arrays in JavaScript
- Checking digit sum of smallest number in the array in JavaScript
- Rearrange An Array In Order – Smallest, Largest, 2nd Smallest, 2nd Largest,. Using C++
- Java program to find the smallest number in an array
- Smallest Common Multiple of an array of numbers in JavaScript
- Find the difference of largest and the smallest number in an array without sorting it in JavaScript
- Java program to find the 2nd smallest number in an array
- Find the Smallest Positive Number Missing From an Unsorted Array
- Finding the smallest positive integer not present in an array in JavaScript
- Get the number of true/false values in an array using JavaScript?

Advertisements