Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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)
Comment

find smallest number in array js

//Not using Math.min:
const min = function(numbers) {
  let smallestNum = numbers[0];
for(let i = 1; i < numbers.length; i++) {
    if(numbers[i] < smallestNum) {
      smallestNum = numbers[i];   
    }
  }
return smallestNum;
};
Comment

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
Comment

how to find the smallest two numbers in an array javascript

function sumTwoSmallestNumbers(numbers) {  
  numbers = numbers.sort((a, b) => {
    return a - b; });
};  //this will turn the numbers list into the 2 lowest numbers
Comment

how to find smallest number in array js

Array.min = function( array ){
    return Math.min.apply( Math, array );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: compare strings to multiple strings javascript 
Javascript :: Below Means Person is A Constructor Function 
Javascript :: how to uitree clone in jquery 
Javascript :: pushReplacement Method 
Javascript :: JSON: remember you can use a value that comes later 
Javascript :: Prototype Constructor Will Be Class or Function 
Javascript :: Automatic update javascript fileversion 
Javascript :: Example Of _.extend 
Javascript :: _.isEqual Underscore Example 
Javascript :: check first path of url js 
Javascript :: Another _.extend Example 
Javascript :: react native tinder 
Javascript :: map function usage in frontend 
Javascript :: telerik mvc grid add row 
Javascript :: make navigation open when items are active 
Javascript :: javascript Program for sum of arithmetic series using loop 
Javascript :: sort list by likes in javascript 
Javascript :: Bootstrap 5 data attributes different from Bootstrap 4 
Javascript :: prisma.db firebase 
Javascript :: react native avoid keyboard when multiline 
Javascript :: add image to center in canvas 
Javascript :: get window object in nextjs 
Javascript :: count repeated characters in a string in react 
Javascript :: create useTransaction 
Javascript :: mui datatable onrowdelete 
Javascript :: Plumsail add a button to the left side of the toolbar, which will be hidden until an item is selected 
Javascript :: javascript reduce form object 
Javascript :: react-icons/vsc 
Javascript :: Setting the default value in the drop down list in AngularJS 
Javascript :: angularjs NodeJS server performs POST request, but returns HTTPErrorResponse 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =