Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get second low value in js

var arr = [15, 37, 9, 21, 55];
var min = Infinity, secondMin = Infinity; 
for (var i= 0; i< arr.length; i++) {
    if (arr[i]< min) {
        secondMin = min;
        min = arr[i]; 
    } else if (arr[i]< secondMin) {
        secondMin = arr[i]; 
    }
}

console.log('Smallest number: ' + min);
console.log('Second smallest number: ' + secondMin);
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to see a mongo document in a pretty mode 
Javascript :: cypress replace response part 
Javascript :: replace html encodings node.js 
Javascript :: nuxt auth no provider 
Javascript :: reactrouter 
Javascript :: javascript use numbers as objects 
Javascript :: get decimal on number javscri 
Javascript :: how to make local storage read only site:stackoverflow.com 
Javascript :: child to perent data transfer in angular 
Javascript :: nodejs sqlite3 db. insert 
Javascript :: getComments 
Javascript :: declerative and imperative program combine 
Javascript :: setFocus() in searchbar ionic4 
Javascript :: how to create a tag object in jQuery 
Javascript :: Getting current location from browser Chrome and Firefox console 
Javascript :: next.js and go 
Javascript :: Return A "Constructor" Function 
Javascript :: react using set Interval date time 
Javascript :: Backbone Initialize Arguments 
Javascript :: get user id from username discord 
Javascript :: javascript Detect Cycle in a Directed Graph 
Javascript :: how to style on-click in react/ vuejs router 
Javascript :: pro side nav react rtl 
Javascript :: populate strapi v4 
Javascript :: sum, rest, ..., ...args 
Javascript :: multiple populate on same level 
Javascript :: for loop increment by more than one 
Javascript :: js to jsx 
Javascript :: d3 js date scatter plot 
Javascript :: cycle 2 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =