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 length string in an array js

var arr = ["aaaa", "aa", "aa", "aaaaa", "a", "aaaaaaaa"];

console.log(
  arr.reduce((a, b) => a.length <= b.length ? a : b)
)
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 smallest number in array js

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

find smallest length string in an array js

var arr = ['cats', 'giants', 'daughters', 'ice'];
var min = Math.min(...arr.map(({ length }) => length));
console.log(min);
Comment

Find Smallest Number by function in Javascript

function smallestNumber(first, second, third) {
    if (first < second && first < third) {
        return first;
    } else if (second < first && second < third) {
        return second;
    } else {
        return third;
    }
}
const num1 = 100;
const num2 = 120;
const num3 = 80;
console.log(smallestNumber(num1, num2, num3));
//Output: 80
Comment

get smallest value in array js

var test=[1, 2, 4, 77, 80];
console.log("Smallest number in test: "+Math.floor(Math.min(test)));
Comment

PREVIOUS NEXT
Code Example
Javascript :: for loop in shopify liquid template 
Javascript :: node terminal readline console 
Javascript :: regex check if number is greater than 
Javascript :: javaScript (DOM) HTML Element by Id 
Javascript :: mongodb empty an array field 
Javascript :: slice string js 
Javascript :: how to pass custom regex in jquery validation 
Javascript :: password validation in regex 
Javascript :: discord.js get user by username 
Javascript :: us postal code regex 
Javascript :: latitude longitude to km javascript 
Javascript :: twilio sms sending in express 
Javascript :: Change the text inside the <p tag: 
Javascript :: convert a date into timestamp in javascript 
Javascript :: hex string to decimal string javascript 
Javascript :: json data example 
Javascript :: TYPING TEXT USING JS 
Javascript :: ajouter javascript dans html 
Javascript :: docker remove json log 
Javascript :: vue axios post return json data 
Javascript :: foreach loop in nodejs 
Javascript :: react eslint prettier 
Javascript :: spring react 
Javascript :: export javascript 
Javascript :: dropzone remove error file 
Javascript :: use $ instead of jQuery 
Javascript :: anagram 
Javascript :: check a date is between two dates in javascript 
Javascript :: html canvas not clearing 
Javascript :: javascript convert input to lowercase 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =