If performance doesn’t bother you then simply sort the array and get the 1 index value of the array to get the second smallest number in array JavaScript.
Find the second smallest number in array JavaScript Example
HTML example code:
Sort method will update existing array in increasing order.
<!DOCTYPE html>
<html>
<body>
<script>
var arr = [2, 1, 9, 5, 7];
var smallest = arr.sort((a, b) => a - b);
alert(smallest[1]);
</script>
</body>
</html>
Output:
Note: Array index is start from 0.
Do comment if you have any doubt and suggesiton on this JS array topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version