javascript find smallest number in an array
const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4] const min = Math.min(...arr) console.log(min)
Source: stackoverflow.com
Find smallest Number from array in javascript
function smallestElemnts(numbers) { var smallest = numbers[0]; for (let i = 0; i < numbers.length; i++) { var elements = numbers[i]; if (elements < smallest) { smallest = elements; } } return smallest; } const numbers = [2, 3, 4, 8, 5, 2, 4]; console.log(smallestElemnts(numbers)); //Output: 2
get smallest value in array js
var test=[1, 2, 4, 77, 80]; console.log("Smallest number in test: "+Math.floor(Math.min(test)));
kth smallest element in an array js
function kthSmallest(arr, k) { arr.sort(function (a, b) { return a - b }) return arr[k - 1] } console.log(kthSmallest([7, 10, 4, 3, 20, 15], 2))