Getting the lowest value with key in array The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceget key from a javascript object with minimum valueCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?Checking if a key exists in a JavaScript object?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Copy array by valueFor-each over an array in JavaScript?

Wolves and sheep

Sort a list of pairs representing an acyclic, partial automorphism

He got a vote 80% that of Emmanuel Macron’s

system() function string length limit

Why did all the guest students take carriages to the Yule Ball?

In horse breeding, what is the female equivalent of putting a horse out "to stud"?

Would an alien lifeform be able to achieve space travel if lacking in vision?

Are my PIs rude or am I just being too sensitive?

Is above average number of years spent on PhD considered a red flag in future academia or industry positions?

Is there a writing software that you can sort scenes like slides in PowerPoint?

Match Roman Numerals

What aspect of planet Earth must be changed to prevent the industrial revolution?

Python - Fishing Simulator

Who or what is the being for whom Being is a question for Heidegger?

What's the point in a preamp?

Does Parliament hold absolute power in the UK?

Can a 1st-level character have an ability score above 18?

How do you keep chess fun when your opponent constantly beats you?

Do warforged have souls?

Did God make two great lights or did He make the great light two?

University's motivation for having tenure-track positions

Typeface like Times New Roman but with "tied" percent sign

Relations between two reciprocal partial derivatives?

When did F become S in typeography, and why?



Getting the lowest value with key in array



The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceget key from a javascript object with minimum valueCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?Checking if a key exists in a JavaScript object?Sort array of objects by string property valueLoop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Copy array by valueFor-each over an array in JavaScript?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








15















I have an array like this: arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, …



And I'm trying get the lowest value with key using Javascript.



What I've tried:



alert(Math.min.apply(Math, arr)); returns Infinity I don't know why



I got this on Google, just for try:



var keys = Object.keys(arr).map(Number).filter(function(a)
return arr[a];
); alert(Math.min.apply(Math, keys));


returns Infinity too



I want something more complete, like this output: "The lowest value is 2 from lst9".



I really tried fix it myself before asking here, but without success!
Can you help me fix this "Infinity" issue? Thank you.










share|improve this question
























  • What is expected output?

    – Maheer Ali
    Mar 25 at 6:45






  • 3





    Do you want to get, for example, lst3 if obj.lst3 is the lowest value?

    – Jack Bashford
    Mar 25 at 6:47






  • 3





    Also, what is lst9? Is it lst9: 2?

    – Jack Bashford
    Mar 25 at 6:48











  • may be a duplicte of stackoverflow.com/questions/38008307/…

    – Syed Mehtab Hassan
    Mar 25 at 6:49







  • 10





    arr is not an array but an object

    – Isaac
    Mar 25 at 6:53

















15















I have an array like this: arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, …



And I'm trying get the lowest value with key using Javascript.



What I've tried:



alert(Math.min.apply(Math, arr)); returns Infinity I don't know why



I got this on Google, just for try:



var keys = Object.keys(arr).map(Number).filter(function(a)
return arr[a];
); alert(Math.min.apply(Math, keys));


returns Infinity too



I want something more complete, like this output: "The lowest value is 2 from lst9".



I really tried fix it myself before asking here, but without success!
Can you help me fix this "Infinity" issue? Thank you.










share|improve this question
























  • What is expected output?

    – Maheer Ali
    Mar 25 at 6:45






  • 3





    Do you want to get, for example, lst3 if obj.lst3 is the lowest value?

    – Jack Bashford
    Mar 25 at 6:47






  • 3





    Also, what is lst9? Is it lst9: 2?

    – Jack Bashford
    Mar 25 at 6:48











  • may be a duplicte of stackoverflow.com/questions/38008307/…

    – Syed Mehtab Hassan
    Mar 25 at 6:49







  • 10





    arr is not an array but an object

    – Isaac
    Mar 25 at 6:53













15












15








15


2






I have an array like this: arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, …



And I'm trying get the lowest value with key using Javascript.



What I've tried:



alert(Math.min.apply(Math, arr)); returns Infinity I don't know why



I got this on Google, just for try:



var keys = Object.keys(arr).map(Number).filter(function(a)
return arr[a];
); alert(Math.min.apply(Math, keys));


returns Infinity too



I want something more complete, like this output: "The lowest value is 2 from lst9".



I really tried fix it myself before asking here, but without success!
Can you help me fix this "Infinity" issue? Thank you.










share|improve this question
















I have an array like this: arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, …



And I'm trying get the lowest value with key using Javascript.



What I've tried:



alert(Math.min.apply(Math, arr)); returns Infinity I don't know why



I got this on Google, just for try:



var keys = Object.keys(arr).map(Number).filter(function(a)
return arr[a];
); alert(Math.min.apply(Math, keys));


returns Infinity too



I want something more complete, like this output: "The lowest value is 2 from lst9".



I really tried fix it myself before asking here, but without success!
Can you help me fix this "Infinity" issue? Thank you.







javascript arrays object






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 20:38









Jack Bashford

16.3k41848




16.3k41848










asked Mar 25 at 6:44









MerntMernt

845




845












  • What is expected output?

    – Maheer Ali
    Mar 25 at 6:45






  • 3





    Do you want to get, for example, lst3 if obj.lst3 is the lowest value?

    – Jack Bashford
    Mar 25 at 6:47






  • 3





    Also, what is lst9? Is it lst9: 2?

    – Jack Bashford
    Mar 25 at 6:48











  • may be a duplicte of stackoverflow.com/questions/38008307/…

    – Syed Mehtab Hassan
    Mar 25 at 6:49







  • 10





    arr is not an array but an object

    – Isaac
    Mar 25 at 6:53

















  • What is expected output?

    – Maheer Ali
    Mar 25 at 6:45






  • 3





    Do you want to get, for example, lst3 if obj.lst3 is the lowest value?

    – Jack Bashford
    Mar 25 at 6:47






  • 3





    Also, what is lst9? Is it lst9: 2?

    – Jack Bashford
    Mar 25 at 6:48











  • may be a duplicte of stackoverflow.com/questions/38008307/…

    – Syed Mehtab Hassan
    Mar 25 at 6:49







  • 10





    arr is not an array but an object

    – Isaac
    Mar 25 at 6:53
















What is expected output?

– Maheer Ali
Mar 25 at 6:45





What is expected output?

– Maheer Ali
Mar 25 at 6:45




3




3





Do you want to get, for example, lst3 if obj.lst3 is the lowest value?

– Jack Bashford
Mar 25 at 6:47





Do you want to get, for example, lst3 if obj.lst3 is the lowest value?

– Jack Bashford
Mar 25 at 6:47




3




3





Also, what is lst9? Is it lst9: 2?

– Jack Bashford
Mar 25 at 6:48





Also, what is lst9? Is it lst9: 2?

– Jack Bashford
Mar 25 at 6:48













may be a duplicte of stackoverflow.com/questions/38008307/…

– Syed Mehtab Hassan
Mar 25 at 6:49






may be a duplicte of stackoverflow.com/questions/38008307/…

– Syed Mehtab Hassan
Mar 25 at 6:49





10




10





arr is not an array but an object

– Isaac
Mar 25 at 6:53





arr is not an array but an object

– Isaac
Mar 25 at 6:53












9 Answers
9






active

oldest

votes


















14














You can get the key and value using Object.entries:






var arr = 
lst1: 300,
lst2: 381,
lst3: 4,
lst4: 4,
lst5: 49
;

function lowestValueAndKey(obj)
var lowestItems = Object.entries(obj).sort(([ ,v1], [ ,v2]) => v1 - v2)[0];
return `Lowest value is $lowestItems[1], with a key of $lowestItems[0]`;


var lowest = lowestValueAndKey(arr);
console.log(lowest);








share|improve this answer


















  • 1





    Hello, Are there an way to make this script compatible with Internet Explorer too?

    – Mernt
    Mar 25 at 7:41











  • @Mernt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

    – JollyJoker
    Mar 25 at 7:59











  • I tried but I'm getting a syntax error on line var lowestItems = Object.entries(arr).sort(([ ,v1], [ ,v2]) => v1 - v2)[0]

    – Mernt
    Mar 25 at 8:06











  • If you look here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… you'll see that Internet Explorer does not support Object.entries

    – ChatterOne
    Mar 25 at 8:08






  • 2





    @Mernt IE doesn't support the fat arrow notation. You need to rewrite ([ ,v1], [ ,v2]) => v1 - v2 in old style Javascript

    – JollyJoker
    Mar 25 at 8:12


















9














There are several ways to arrive at what you want. Please see the following methods:






const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49 
const values = Object.values(obj)
const lowest = Math.min.apply(null, values)

// Using Object.keys(), Object.values() and findIndex()
const keys = Object.keys(obj)
const indexOfLowest = values.findIndex(function (x) return x === lowest )
console.log(`The lowest value is $lowest from $keys[indexOfLowest]`)



// OR Using Object.keys() and filter()
const key = Object.keys(obj).filter(function (x) return obj[x] === lowest )[0]
console.log(`The lowest value is $lowest from $key`)



// OR Using Object.entries() and sort()
const [[lowestKey, lowestVal]] = Object.entries(obj).sort(function ([,valA], [,valB]) return valA - valB );
console.log(`The lowest value is $lowestVal from $lowestKey`)








share|improve this answer

























  • It should work as is in IE > = 11

    – John Kennedy
    Mar 25 at 8:02











  • Syntax error on line var key = Object.keys(arr).filter(x => arr[x] === lowest)[0]

    – Mernt
    Mar 25 at 8:08






  • 1





    I'll suggest using a polyfill if it doesn't work in IE. See here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I should also inform you that on my IE on Windows 10 it works without needing a polyfill.

    – John Kennedy
    Mar 25 at 8:10







  • 1





    @JohnKennedy I'd be surprised by that, IE doesn't support arrow functions

    – Nick A
    Mar 25 at 14:47


















8














There are many ways to approach your problem, but here is one simple alternative way to do it. Basically, it is a brute force way of doing things, whereby you iterate through every property to check for the value.



const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;

const getSmallest = function (object)
let smallestValue = Number.MAX_VALUE;
let selectedKey = '';
for (let key in object)
if (object[key] < smallestValue)
smallestValue = object[key];
selectedKey = key;

;
console.log(selectedKey, smallestValue)
return `The lowest value is $smallestValue from $selectedKey`;
;

getSmallest(obj);





share|improve this answer
































    4














    To get only the minimum number you can use Math.min(...Object.entries(arr).map(o => o[1])):






    const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
    const lowestValue = Math.min(...Object.entries(arr).map(o => o[1]));

    console.log(lowestValue);





    And to get the object with the minimum value you can use Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, ):






    const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
    const lowestObj = Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, );

    console.log(lowestObj);








    share|improve this answer
































      3














      Here we first assume that the min, key and value as first property and the value respectively. Then we iterate through all the elements and compare with minValue to find any value less than that in the object. If it is, then we update both minValue and minKey. Anyway, the arr type is an Object. it is not an array in javascript.



      var arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
      var minkey = Object.keys(arr)[0];
      var minValue = arr[Object.keys(arr)[0]];
      for (var key in arr)
      if (arr.hasOwnProperty(key))
      if(arr[key] < minValue)
      minValue = arr[key];
      minKey = key;








      share|improve this answer






























        2














        You can try this:



        obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2; // This is an object, That;s ehy you getting infinite

        var arr = Object.keys( obj ).map(function ( key ) return obj[key]; );

        alert(Math.min.apply( null, arr ));


        Fiddle: https://jsfiddle.net/ozvubmdr/






        share|improve this answer






























          2














          Easy, though not optimal, as it traverses the array twice: find the smallest value, then find the key belonging to it.






          arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
          min = Math.min(...Object.values(arr));
          minkey = Object.keys(arr).find(key => arr[key] = min);
          console.log(`Lowest is $min at $minkey`);








          share|improve this answer






























            2














            You may try this:






            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
            const minVal = Math.min(...Object.values(arr))
            const fromKey = Object.keys(arr).find(key => arr[key] === minVal)
            console.log(`The lowest value is $minVal from $fromKey`)








            share|improve this answer






























              2














              You can use Object.entries and use Array.reduce to reduce the resulting [key-value] pair to an object which will have lowest entry:






              const data = lst1: 300, lst2: -381, lst3: 4, lst4: 4, lst5: 49, lst6: -49, lst7: 0, lst7: 78, lst7: -90;
              const obj = Object.entries(data).reduce((acc, [key, value]) =>
              acc["lowest"] = acc["lowest"] ? Object.values(acc["lowest"])[0] < value ? acc["lowest"] : [key] : value : [key] : value ;
              return acc;
              , );
              console.log(`Lowest value is found in $JSON.stringify(obj.lowest)`);








              share|improve this answer

























                Your Answer






                StackExchange.ifUsing("editor", function ()
                StackExchange.using("externalEditor", function ()
                StackExchange.using("snippets", function ()
                StackExchange.snippets.init();
                );
                );
                , "code-snippets");

                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "1"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332453%2fgetting-the-lowest-value-with-key-in-array%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                9 Answers
                9






                active

                oldest

                votes








                9 Answers
                9






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                14














                You can get the key and value using Object.entries:






                var arr = 
                lst1: 300,
                lst2: 381,
                lst3: 4,
                lst4: 4,
                lst5: 49
                ;

                function lowestValueAndKey(obj)
                var lowestItems = Object.entries(obj).sort(([ ,v1], [ ,v2]) => v1 - v2)[0];
                return `Lowest value is $lowestItems[1], with a key of $lowestItems[0]`;


                var lowest = lowestValueAndKey(arr);
                console.log(lowest);








                share|improve this answer


















                • 1





                  Hello, Are there an way to make this script compatible with Internet Explorer too?

                  – Mernt
                  Mar 25 at 7:41











                • @Mernt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

                  – JollyJoker
                  Mar 25 at 7:59











                • I tried but I'm getting a syntax error on line var lowestItems = Object.entries(arr).sort(([ ,v1], [ ,v2]) => v1 - v2)[0]

                  – Mernt
                  Mar 25 at 8:06











                • If you look here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… you'll see that Internet Explorer does not support Object.entries

                  – ChatterOne
                  Mar 25 at 8:08






                • 2





                  @Mernt IE doesn't support the fat arrow notation. You need to rewrite ([ ,v1], [ ,v2]) => v1 - v2 in old style Javascript

                  – JollyJoker
                  Mar 25 at 8:12















                14














                You can get the key and value using Object.entries:






                var arr = 
                lst1: 300,
                lst2: 381,
                lst3: 4,
                lst4: 4,
                lst5: 49
                ;

                function lowestValueAndKey(obj)
                var lowestItems = Object.entries(obj).sort(([ ,v1], [ ,v2]) => v1 - v2)[0];
                return `Lowest value is $lowestItems[1], with a key of $lowestItems[0]`;


                var lowest = lowestValueAndKey(arr);
                console.log(lowest);








                share|improve this answer


















                • 1





                  Hello, Are there an way to make this script compatible with Internet Explorer too?

                  – Mernt
                  Mar 25 at 7:41











                • @Mernt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

                  – JollyJoker
                  Mar 25 at 7:59











                • I tried but I'm getting a syntax error on line var lowestItems = Object.entries(arr).sort(([ ,v1], [ ,v2]) => v1 - v2)[0]

                  – Mernt
                  Mar 25 at 8:06











                • If you look here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… you'll see that Internet Explorer does not support Object.entries

                  – ChatterOne
                  Mar 25 at 8:08






                • 2





                  @Mernt IE doesn't support the fat arrow notation. You need to rewrite ([ ,v1], [ ,v2]) => v1 - v2 in old style Javascript

                  – JollyJoker
                  Mar 25 at 8:12













                14












                14








                14







                You can get the key and value using Object.entries:






                var arr = 
                lst1: 300,
                lst2: 381,
                lst3: 4,
                lst4: 4,
                lst5: 49
                ;

                function lowestValueAndKey(obj)
                var lowestItems = Object.entries(obj).sort(([ ,v1], [ ,v2]) => v1 - v2)[0];
                return `Lowest value is $lowestItems[1], with a key of $lowestItems[0]`;


                var lowest = lowestValueAndKey(arr);
                console.log(lowest);








                share|improve this answer













                You can get the key and value using Object.entries:






                var arr = 
                lst1: 300,
                lst2: 381,
                lst3: 4,
                lst4: 4,
                lst5: 49
                ;

                function lowestValueAndKey(obj)
                var lowestItems = Object.entries(obj).sort(([ ,v1], [ ,v2]) => v1 - v2)[0];
                return `Lowest value is $lowestItems[1], with a key of $lowestItems[0]`;


                var lowest = lowestValueAndKey(arr);
                console.log(lowest);








                var arr = 
                lst1: 300,
                lst2: 381,
                lst3: 4,
                lst4: 4,
                lst5: 49
                ;

                function lowestValueAndKey(obj)
                var lowestItems = Object.entries(obj).sort(([ ,v1], [ ,v2]) => v1 - v2)[0];
                return `Lowest value is $lowestItems[1], with a key of $lowestItems[0]`;


                var lowest = lowestValueAndKey(arr);
                console.log(lowest);





                var arr = 
                lst1: 300,
                lst2: 381,
                lst3: 4,
                lst4: 4,
                lst5: 49
                ;

                function lowestValueAndKey(obj)
                var lowestItems = Object.entries(obj).sort(([ ,v1], [ ,v2]) => v1 - v2)[0];
                return `Lowest value is $lowestItems[1], with a key of $lowestItems[0]`;


                var lowest = lowestValueAndKey(arr);
                console.log(lowest);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 25 at 6:54









                Jack BashfordJack Bashford

                16.3k41848




                16.3k41848







                • 1





                  Hello, Are there an way to make this script compatible with Internet Explorer too?

                  – Mernt
                  Mar 25 at 7:41











                • @Mernt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

                  – JollyJoker
                  Mar 25 at 7:59











                • I tried but I'm getting a syntax error on line var lowestItems = Object.entries(arr).sort(([ ,v1], [ ,v2]) => v1 - v2)[0]

                  – Mernt
                  Mar 25 at 8:06











                • If you look here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… you'll see that Internet Explorer does not support Object.entries

                  – ChatterOne
                  Mar 25 at 8:08






                • 2





                  @Mernt IE doesn't support the fat arrow notation. You need to rewrite ([ ,v1], [ ,v2]) => v1 - v2 in old style Javascript

                  – JollyJoker
                  Mar 25 at 8:12












                • 1





                  Hello, Are there an way to make this script compatible with Internet Explorer too?

                  – Mernt
                  Mar 25 at 7:41











                • @Mernt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

                  – JollyJoker
                  Mar 25 at 7:59











                • I tried but I'm getting a syntax error on line var lowestItems = Object.entries(arr).sort(([ ,v1], [ ,v2]) => v1 - v2)[0]

                  – Mernt
                  Mar 25 at 8:06











                • If you look here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… you'll see that Internet Explorer does not support Object.entries

                  – ChatterOne
                  Mar 25 at 8:08






                • 2





                  @Mernt IE doesn't support the fat arrow notation. You need to rewrite ([ ,v1], [ ,v2]) => v1 - v2 in old style Javascript

                  – JollyJoker
                  Mar 25 at 8:12







                1




                1





                Hello, Are there an way to make this script compatible with Internet Explorer too?

                – Mernt
                Mar 25 at 7:41





                Hello, Are there an way to make this script compatible with Internet Explorer too?

                – Mernt
                Mar 25 at 7:41













                @Mernt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

                – JollyJoker
                Mar 25 at 7:59





                @Mernt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…

                – JollyJoker
                Mar 25 at 7:59













                I tried but I'm getting a syntax error on line var lowestItems = Object.entries(arr).sort(([ ,v1], [ ,v2]) => v1 - v2)[0]

                – Mernt
                Mar 25 at 8:06





                I tried but I'm getting a syntax error on line var lowestItems = Object.entries(arr).sort(([ ,v1], [ ,v2]) => v1 - v2)[0]

                – Mernt
                Mar 25 at 8:06













                If you look here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… you'll see that Internet Explorer does not support Object.entries

                – ChatterOne
                Mar 25 at 8:08





                If you look here developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… you'll see that Internet Explorer does not support Object.entries

                – ChatterOne
                Mar 25 at 8:08




                2




                2





                @Mernt IE doesn't support the fat arrow notation. You need to rewrite ([ ,v1], [ ,v2]) => v1 - v2 in old style Javascript

                – JollyJoker
                Mar 25 at 8:12





                @Mernt IE doesn't support the fat arrow notation. You need to rewrite ([ ,v1], [ ,v2]) => v1 - v2 in old style Javascript

                – JollyJoker
                Mar 25 at 8:12













                9














                There are several ways to arrive at what you want. Please see the following methods:






                const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49 
                const values = Object.values(obj)
                const lowest = Math.min.apply(null, values)

                // Using Object.keys(), Object.values() and findIndex()
                const keys = Object.keys(obj)
                const indexOfLowest = values.findIndex(function (x) return x === lowest )
                console.log(`The lowest value is $lowest from $keys[indexOfLowest]`)



                // OR Using Object.keys() and filter()
                const key = Object.keys(obj).filter(function (x) return obj[x] === lowest )[0]
                console.log(`The lowest value is $lowest from $key`)



                // OR Using Object.entries() and sort()
                const [[lowestKey, lowestVal]] = Object.entries(obj).sort(function ([,valA], [,valB]) return valA - valB );
                console.log(`The lowest value is $lowestVal from $lowestKey`)








                share|improve this answer

























                • It should work as is in IE > = 11

                  – John Kennedy
                  Mar 25 at 8:02











                • Syntax error on line var key = Object.keys(arr).filter(x => arr[x] === lowest)[0]

                  – Mernt
                  Mar 25 at 8:08






                • 1





                  I'll suggest using a polyfill if it doesn't work in IE. See here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I should also inform you that on my IE on Windows 10 it works without needing a polyfill.

                  – John Kennedy
                  Mar 25 at 8:10







                • 1





                  @JohnKennedy I'd be surprised by that, IE doesn't support arrow functions

                  – Nick A
                  Mar 25 at 14:47















                9














                There are several ways to arrive at what you want. Please see the following methods:






                const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49 
                const values = Object.values(obj)
                const lowest = Math.min.apply(null, values)

                // Using Object.keys(), Object.values() and findIndex()
                const keys = Object.keys(obj)
                const indexOfLowest = values.findIndex(function (x) return x === lowest )
                console.log(`The lowest value is $lowest from $keys[indexOfLowest]`)



                // OR Using Object.keys() and filter()
                const key = Object.keys(obj).filter(function (x) return obj[x] === lowest )[0]
                console.log(`The lowest value is $lowest from $key`)



                // OR Using Object.entries() and sort()
                const [[lowestKey, lowestVal]] = Object.entries(obj).sort(function ([,valA], [,valB]) return valA - valB );
                console.log(`The lowest value is $lowestVal from $lowestKey`)








                share|improve this answer

























                • It should work as is in IE > = 11

                  – John Kennedy
                  Mar 25 at 8:02











                • Syntax error on line var key = Object.keys(arr).filter(x => arr[x] === lowest)[0]

                  – Mernt
                  Mar 25 at 8:08






                • 1





                  I'll suggest using a polyfill if it doesn't work in IE. See here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I should also inform you that on my IE on Windows 10 it works without needing a polyfill.

                  – John Kennedy
                  Mar 25 at 8:10







                • 1





                  @JohnKennedy I'd be surprised by that, IE doesn't support arrow functions

                  – Nick A
                  Mar 25 at 14:47













                9












                9








                9







                There are several ways to arrive at what you want. Please see the following methods:






                const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49 
                const values = Object.values(obj)
                const lowest = Math.min.apply(null, values)

                // Using Object.keys(), Object.values() and findIndex()
                const keys = Object.keys(obj)
                const indexOfLowest = values.findIndex(function (x) return x === lowest )
                console.log(`The lowest value is $lowest from $keys[indexOfLowest]`)



                // OR Using Object.keys() and filter()
                const key = Object.keys(obj).filter(function (x) return obj[x] === lowest )[0]
                console.log(`The lowest value is $lowest from $key`)



                // OR Using Object.entries() and sort()
                const [[lowestKey, lowestVal]] = Object.entries(obj).sort(function ([,valA], [,valB]) return valA - valB );
                console.log(`The lowest value is $lowestVal from $lowestKey`)








                share|improve this answer















                There are several ways to arrive at what you want. Please see the following methods:






                const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49 
                const values = Object.values(obj)
                const lowest = Math.min.apply(null, values)

                // Using Object.keys(), Object.values() and findIndex()
                const keys = Object.keys(obj)
                const indexOfLowest = values.findIndex(function (x) return x === lowest )
                console.log(`The lowest value is $lowest from $keys[indexOfLowest]`)



                // OR Using Object.keys() and filter()
                const key = Object.keys(obj).filter(function (x) return obj[x] === lowest )[0]
                console.log(`The lowest value is $lowest from $key`)



                // OR Using Object.entries() and sort()
                const [[lowestKey, lowestVal]] = Object.entries(obj).sort(function ([,valA], [,valB]) return valA - valB );
                console.log(`The lowest value is $lowestVal from $lowestKey`)








                const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49 
                const values = Object.values(obj)
                const lowest = Math.min.apply(null, values)

                // Using Object.keys(), Object.values() and findIndex()
                const keys = Object.keys(obj)
                const indexOfLowest = values.findIndex(function (x) return x === lowest )
                console.log(`The lowest value is $lowest from $keys[indexOfLowest]`)



                // OR Using Object.keys() and filter()
                const key = Object.keys(obj).filter(function (x) return obj[x] === lowest )[0]
                console.log(`The lowest value is $lowest from $key`)



                // OR Using Object.entries() and sort()
                const [[lowestKey, lowestVal]] = Object.entries(obj).sort(function ([,valA], [,valB]) return valA - valB );
                console.log(`The lowest value is $lowestVal from $lowestKey`)





                const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49 
                const values = Object.values(obj)
                const lowest = Math.min.apply(null, values)

                // Using Object.keys(), Object.values() and findIndex()
                const keys = Object.keys(obj)
                const indexOfLowest = values.findIndex(function (x) return x === lowest )
                console.log(`The lowest value is $lowest from $keys[indexOfLowest]`)



                // OR Using Object.keys() and filter()
                const key = Object.keys(obj).filter(function (x) return obj[x] === lowest )[0]
                console.log(`The lowest value is $lowest from $key`)



                // OR Using Object.entries() and sort()
                const [[lowestKey, lowestVal]] = Object.entries(obj).sort(function ([,valA], [,valB]) return valA - valB );
                console.log(`The lowest value is $lowestVal from $lowestKey`)






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 21:42

























                answered Mar 25 at 6:53









                John KennedyJohn Kennedy

                3,07321329




                3,07321329












                • It should work as is in IE > = 11

                  – John Kennedy
                  Mar 25 at 8:02











                • Syntax error on line var key = Object.keys(arr).filter(x => arr[x] === lowest)[0]

                  – Mernt
                  Mar 25 at 8:08






                • 1





                  I'll suggest using a polyfill if it doesn't work in IE. See here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I should also inform you that on my IE on Windows 10 it works without needing a polyfill.

                  – John Kennedy
                  Mar 25 at 8:10







                • 1





                  @JohnKennedy I'd be surprised by that, IE doesn't support arrow functions

                  – Nick A
                  Mar 25 at 14:47

















                • It should work as is in IE > = 11

                  – John Kennedy
                  Mar 25 at 8:02











                • Syntax error on line var key = Object.keys(arr).filter(x => arr[x] === lowest)[0]

                  – Mernt
                  Mar 25 at 8:08






                • 1





                  I'll suggest using a polyfill if it doesn't work in IE. See here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I should also inform you that on my IE on Windows 10 it works without needing a polyfill.

                  – John Kennedy
                  Mar 25 at 8:10







                • 1





                  @JohnKennedy I'd be surprised by that, IE doesn't support arrow functions

                  – Nick A
                  Mar 25 at 14:47
















                It should work as is in IE > = 11

                – John Kennedy
                Mar 25 at 8:02





                It should work as is in IE > = 11

                – John Kennedy
                Mar 25 at 8:02













                Syntax error on line var key = Object.keys(arr).filter(x => arr[x] === lowest)[0]

                – Mernt
                Mar 25 at 8:08





                Syntax error on line var key = Object.keys(arr).filter(x => arr[x] === lowest)[0]

                – Mernt
                Mar 25 at 8:08




                1




                1





                I'll suggest using a polyfill if it doesn't work in IE. See here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I should also inform you that on my IE on Windows 10 it works without needing a polyfill.

                – John Kennedy
                Mar 25 at 8:10






                I'll suggest using a polyfill if it doesn't work in IE. See here: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… I should also inform you that on my IE on Windows 10 it works without needing a polyfill.

                – John Kennedy
                Mar 25 at 8:10





                1




                1





                @JohnKennedy I'd be surprised by that, IE doesn't support arrow functions

                – Nick A
                Mar 25 at 14:47





                @JohnKennedy I'd be surprised by that, IE doesn't support arrow functions

                – Nick A
                Mar 25 at 14:47











                8














                There are many ways to approach your problem, but here is one simple alternative way to do it. Basically, it is a brute force way of doing things, whereby you iterate through every property to check for the value.



                const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;

                const getSmallest = function (object)
                let smallestValue = Number.MAX_VALUE;
                let selectedKey = '';
                for (let key in object)
                if (object[key] < smallestValue)
                smallestValue = object[key];
                selectedKey = key;

                ;
                console.log(selectedKey, smallestValue)
                return `The lowest value is $smallestValue from $selectedKey`;
                ;

                getSmallest(obj);





                share|improve this answer





























                  8














                  There are many ways to approach your problem, but here is one simple alternative way to do it. Basically, it is a brute force way of doing things, whereby you iterate through every property to check for the value.



                  const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;

                  const getSmallest = function (object)
                  let smallestValue = Number.MAX_VALUE;
                  let selectedKey = '';
                  for (let key in object)
                  if (object[key] < smallestValue)
                  smallestValue = object[key];
                  selectedKey = key;

                  ;
                  console.log(selectedKey, smallestValue)
                  return `The lowest value is $smallestValue from $selectedKey`;
                  ;

                  getSmallest(obj);





                  share|improve this answer



























                    8












                    8








                    8







                    There are many ways to approach your problem, but here is one simple alternative way to do it. Basically, it is a brute force way of doing things, whereby you iterate through every property to check for the value.



                    const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;

                    const getSmallest = function (object)
                    let smallestValue = Number.MAX_VALUE;
                    let selectedKey = '';
                    for (let key in object)
                    if (object[key] < smallestValue)
                    smallestValue = object[key];
                    selectedKey = key;

                    ;
                    console.log(selectedKey, smallestValue)
                    return `The lowest value is $smallestValue from $selectedKey`;
                    ;

                    getSmallest(obj);





                    share|improve this answer















                    There are many ways to approach your problem, but here is one simple alternative way to do it. Basically, it is a brute force way of doing things, whereby you iterate through every property to check for the value.



                    const obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;

                    const getSmallest = function (object)
                    let smallestValue = Number.MAX_VALUE;
                    let selectedKey = '';
                    for (let key in object)
                    if (object[key] < smallestValue)
                    smallestValue = object[key];
                    selectedKey = key;

                    ;
                    console.log(selectedKey, smallestValue)
                    return `The lowest value is $smallestValue from $selectedKey`;
                    ;

                    getSmallest(obj);






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 25 at 8:12

























                    answered Mar 25 at 6:55







                    user10997785




























                        4














                        To get only the minimum number you can use Math.min(...Object.entries(arr).map(o => o[1])):






                        const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                        const lowestValue = Math.min(...Object.entries(arr).map(o => o[1]));

                        console.log(lowestValue);





                        And to get the object with the minimum value you can use Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, ):






                        const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                        const lowestObj = Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, );

                        console.log(lowestObj);








                        share|improve this answer





























                          4














                          To get only the minimum number you can use Math.min(...Object.entries(arr).map(o => o[1])):






                          const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                          const lowestValue = Math.min(...Object.entries(arr).map(o => o[1]));

                          console.log(lowestValue);





                          And to get the object with the minimum value you can use Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, ):






                          const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                          const lowestObj = Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, );

                          console.log(lowestObj);








                          share|improve this answer



























                            4












                            4








                            4







                            To get only the minimum number you can use Math.min(...Object.entries(arr).map(o => o[1])):






                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestValue = Math.min(...Object.entries(arr).map(o => o[1]));

                            console.log(lowestValue);





                            And to get the object with the minimum value you can use Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, ):






                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestObj = Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, );

                            console.log(lowestObj);








                            share|improve this answer















                            To get only the minimum number you can use Math.min(...Object.entries(arr).map(o => o[1])):






                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestValue = Math.min(...Object.entries(arr).map(o => o[1]));

                            console.log(lowestValue);





                            And to get the object with the minimum value you can use Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, ):






                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestObj = Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, );

                            console.log(lowestObj);








                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestValue = Math.min(...Object.entries(arr).map(o => o[1]));

                            console.log(lowestValue);





                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestValue = Math.min(...Object.entries(arr).map(o => o[1]));

                            console.log(lowestValue);





                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestObj = Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, );

                            console.log(lowestObj);





                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                            const lowestObj = Object.entries(arr).reduce((a, [k, v]) => a[Object.keys(a)[0]] < v ? a : [k]: v, );

                            console.log(lowestObj);






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 25 at 8:01

























                            answered Mar 25 at 7:03









                            Yosvel QuinteroYosvel Quintero

                            12.1k42531




                            12.1k42531





















                                3














                                Here we first assume that the min, key and value as first property and the value respectively. Then we iterate through all the elements and compare with minValue to find any value less than that in the object. If it is, then we update both minValue and minKey. Anyway, the arr type is an Object. it is not an array in javascript.



                                var arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                                var minkey = Object.keys(arr)[0];
                                var minValue = arr[Object.keys(arr)[0]];
                                for (var key in arr)
                                if (arr.hasOwnProperty(key))
                                if(arr[key] < minValue)
                                minValue = arr[key];
                                minKey = key;








                                share|improve this answer



























                                  3














                                  Here we first assume that the min, key and value as first property and the value respectively. Then we iterate through all the elements and compare with minValue to find any value less than that in the object. If it is, then we update both minValue and minKey. Anyway, the arr type is an Object. it is not an array in javascript.



                                  var arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                                  var minkey = Object.keys(arr)[0];
                                  var minValue = arr[Object.keys(arr)[0]];
                                  for (var key in arr)
                                  if (arr.hasOwnProperty(key))
                                  if(arr[key] < minValue)
                                  minValue = arr[key];
                                  minKey = key;








                                  share|improve this answer

























                                    3












                                    3








                                    3







                                    Here we first assume that the min, key and value as first property and the value respectively. Then we iterate through all the elements and compare with minValue to find any value less than that in the object. If it is, then we update both minValue and minKey. Anyway, the arr type is an Object. it is not an array in javascript.



                                    var arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                                    var minkey = Object.keys(arr)[0];
                                    var minValue = arr[Object.keys(arr)[0]];
                                    for (var key in arr)
                                    if (arr.hasOwnProperty(key))
                                    if(arr[key] < minValue)
                                    minValue = arr[key];
                                    minKey = key;








                                    share|improve this answer













                                    Here we first assume that the min, key and value as first property and the value respectively. Then we iterate through all the elements and compare with minValue to find any value less than that in the object. If it is, then we update both minValue and minKey. Anyway, the arr type is an Object. it is not an array in javascript.



                                    var arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49;
                                    var minkey = Object.keys(arr)[0];
                                    var minValue = arr[Object.keys(arr)[0]];
                                    for (var key in arr)
                                    if (arr.hasOwnProperty(key))
                                    if(arr[key] < minValue)
                                    minValue = arr[key];
                                    minKey = key;









                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Mar 25 at 7:02









                                    HarshanaHarshana

                                    346212




                                    346212





















                                        2














                                        You can try this:



                                        obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2; // This is an object, That;s ehy you getting infinite

                                        var arr = Object.keys( obj ).map(function ( key ) return obj[key]; );

                                        alert(Math.min.apply( null, arr ));


                                        Fiddle: https://jsfiddle.net/ozvubmdr/






                                        share|improve this answer



























                                          2














                                          You can try this:



                                          obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2; // This is an object, That;s ehy you getting infinite

                                          var arr = Object.keys( obj ).map(function ( key ) return obj[key]; );

                                          alert(Math.min.apply( null, arr ));


                                          Fiddle: https://jsfiddle.net/ozvubmdr/






                                          share|improve this answer

























                                            2












                                            2








                                            2







                                            You can try this:



                                            obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2; // This is an object, That;s ehy you getting infinite

                                            var arr = Object.keys( obj ).map(function ( key ) return obj[key]; );

                                            alert(Math.min.apply( null, arr ));


                                            Fiddle: https://jsfiddle.net/ozvubmdr/






                                            share|improve this answer













                                            You can try this:



                                            obj = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2; // This is an object, That;s ehy you getting infinite

                                            var arr = Object.keys( obj ).map(function ( key ) return obj[key]; );

                                            alert(Math.min.apply( null, arr ));


                                            Fiddle: https://jsfiddle.net/ozvubmdr/







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Mar 25 at 6:51









                                            Ajay MakwanaAjay Makwana

                                            1,537926




                                            1,537926





















                                                2














                                                Easy, though not optimal, as it traverses the array twice: find the smallest value, then find the key belonging to it.






                                                arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                min = Math.min(...Object.values(arr));
                                                minkey = Object.keys(arr).find(key => arr[key] = min);
                                                console.log(`Lowest is $min at $minkey`);








                                                share|improve this answer



























                                                  2














                                                  Easy, though not optimal, as it traverses the array twice: find the smallest value, then find the key belonging to it.






                                                  arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                  min = Math.min(...Object.values(arr));
                                                  minkey = Object.keys(arr).find(key => arr[key] = min);
                                                  console.log(`Lowest is $min at $minkey`);








                                                  share|improve this answer

























                                                    2












                                                    2








                                                    2







                                                    Easy, though not optimal, as it traverses the array twice: find the smallest value, then find the key belonging to it.






                                                    arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                    min = Math.min(...Object.values(arr));
                                                    minkey = Object.keys(arr).find(key => arr[key] = min);
                                                    console.log(`Lowest is $min at $minkey`);








                                                    share|improve this answer













                                                    Easy, though not optimal, as it traverses the array twice: find the smallest value, then find the key belonging to it.






                                                    arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                    min = Math.min(...Object.values(arr));
                                                    minkey = Object.keys(arr).find(key => arr[key] = min);
                                                    console.log(`Lowest is $min at $minkey`);








                                                    arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                    min = Math.min(...Object.values(arr));
                                                    minkey = Object.keys(arr).find(key => arr[key] = min);
                                                    console.log(`Lowest is $min at $minkey`);





                                                    arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                    min = Math.min(...Object.values(arr));
                                                    minkey = Object.keys(arr).find(key => arr[key] = min);
                                                    console.log(`Lowest is $min at $minkey`);






                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Mar 25 at 6:54









                                                    AmadanAmadan

                                                    134k13150201




                                                    134k13150201





















                                                        2














                                                        You may try this:






                                                        const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                        const minVal = Math.min(...Object.values(arr))
                                                        const fromKey = Object.keys(arr).find(key => arr[key] === minVal)
                                                        console.log(`The lowest value is $minVal from $fromKey`)








                                                        share|improve this answer



























                                                          2














                                                          You may try this:






                                                          const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                          const minVal = Math.min(...Object.values(arr))
                                                          const fromKey = Object.keys(arr).find(key => arr[key] === minVal)
                                                          console.log(`The lowest value is $minVal from $fromKey`)








                                                          share|improve this answer

























                                                            2












                                                            2








                                                            2







                                                            You may try this:






                                                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                            const minVal = Math.min(...Object.values(arr))
                                                            const fromKey = Object.keys(arr).find(key => arr[key] === minVal)
                                                            console.log(`The lowest value is $minVal from $fromKey`)








                                                            share|improve this answer













                                                            You may try this:






                                                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                            const minVal = Math.min(...Object.values(arr))
                                                            const fromKey = Object.keys(arr).find(key => arr[key] === minVal)
                                                            console.log(`The lowest value is $minVal from $fromKey`)








                                                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                            const minVal = Math.min(...Object.values(arr))
                                                            const fromKey = Object.keys(arr).find(key => arr[key] === minVal)
                                                            console.log(`The lowest value is $minVal from $fromKey`)





                                                            const arr = lst1: 300, lst2: 381, lst3: 4, lst4: 4, lst5: 49, lst9: 2
                                                            const minVal = Math.min(...Object.values(arr))
                                                            const fromKey = Object.keys(arr).find(key => arr[key] === minVal)
                                                            console.log(`The lowest value is $minVal from $fromKey`)






                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Mar 25 at 6:59









                                                            Pak Wah WongPak Wah Wong

                                                            38317




                                                            38317





















                                                                2














                                                                You can use Object.entries and use Array.reduce to reduce the resulting [key-value] pair to an object which will have lowest entry:






                                                                const data = lst1: 300, lst2: -381, lst3: 4, lst4: 4, lst5: 49, lst6: -49, lst7: 0, lst7: 78, lst7: -90;
                                                                const obj = Object.entries(data).reduce((acc, [key, value]) =>
                                                                acc["lowest"] = acc["lowest"] ? Object.values(acc["lowest"])[0] < value ? acc["lowest"] : [key] : value : [key] : value ;
                                                                return acc;
                                                                , );
                                                                console.log(`Lowest value is found in $JSON.stringify(obj.lowest)`);








                                                                share|improve this answer





























                                                                  2














                                                                  You can use Object.entries and use Array.reduce to reduce the resulting [key-value] pair to an object which will have lowest entry:






                                                                  const data = lst1: 300, lst2: -381, lst3: 4, lst4: 4, lst5: 49, lst6: -49, lst7: 0, lst7: 78, lst7: -90;
                                                                  const obj = Object.entries(data).reduce((acc, [key, value]) =>
                                                                  acc["lowest"] = acc["lowest"] ? Object.values(acc["lowest"])[0] < value ? acc["lowest"] : [key] : value : [key] : value ;
                                                                  return acc;
                                                                  , );
                                                                  console.log(`Lowest value is found in $JSON.stringify(obj.lowest)`);








                                                                  share|improve this answer



























                                                                    2












                                                                    2








                                                                    2







                                                                    You can use Object.entries and use Array.reduce to reduce the resulting [key-value] pair to an object which will have lowest entry:






                                                                    const data = lst1: 300, lst2: -381, lst3: 4, lst4: 4, lst5: 49, lst6: -49, lst7: 0, lst7: 78, lst7: -90;
                                                                    const obj = Object.entries(data).reduce((acc, [key, value]) =>
                                                                    acc["lowest"] = acc["lowest"] ? Object.values(acc["lowest"])[0] < value ? acc["lowest"] : [key] : value : [key] : value ;
                                                                    return acc;
                                                                    , );
                                                                    console.log(`Lowest value is found in $JSON.stringify(obj.lowest)`);








                                                                    share|improve this answer















                                                                    You can use Object.entries and use Array.reduce to reduce the resulting [key-value] pair to an object which will have lowest entry:






                                                                    const data = lst1: 300, lst2: -381, lst3: 4, lst4: 4, lst5: 49, lst6: -49, lst7: 0, lst7: 78, lst7: -90;
                                                                    const obj = Object.entries(data).reduce((acc, [key, value]) =>
                                                                    acc["lowest"] = acc["lowest"] ? Object.values(acc["lowest"])[0] < value ? acc["lowest"] : [key] : value : [key] : value ;
                                                                    return acc;
                                                                    , );
                                                                    console.log(`Lowest value is found in $JSON.stringify(obj.lowest)`);








                                                                    const data = lst1: 300, lst2: -381, lst3: 4, lst4: 4, lst5: 49, lst6: -49, lst7: 0, lst7: 78, lst7: -90;
                                                                    const obj = Object.entries(data).reduce((acc, [key, value]) =>
                                                                    acc["lowest"] = acc["lowest"] ? Object.values(acc["lowest"])[0] < value ? acc["lowest"] : [key] : value : [key] : value ;
                                                                    return acc;
                                                                    , );
                                                                    console.log(`Lowest value is found in $JSON.stringify(obj.lowest)`);





                                                                    const data = lst1: 300, lst2: -381, lst3: 4, lst4: 4, lst5: 49, lst6: -49, lst7: 0, lst7: 78, lst7: -90;
                                                                    const obj = Object.entries(data).reduce((acc, [key, value]) =>
                                                                    acc["lowest"] = acc["lowest"] ? Object.values(acc["lowest"])[0] < value ? acc["lowest"] : [key] : value : [key] : value ;
                                                                    return acc;
                                                                    , );
                                                                    console.log(`Lowest value is found in $JSON.stringify(obj.lowest)`);






                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Mar 25 at 7:30

























                                                                    answered Mar 25 at 7:02









                                                                    Amardeep BhowmickAmardeep Bhowmick

                                                                    5,78121128




                                                                    5,78121128



























                                                                        draft saved

                                                                        draft discarded
















































                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                        But avoid


                                                                        • Asking for help, clarification, or responding to other answers.

                                                                        • Making statements based on opinion; back them up with references or personal experience.

                                                                        To learn more, see our tips on writing great answers.




                                                                        draft saved


                                                                        draft discarded














                                                                        StackExchange.ready(
                                                                        function ()
                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55332453%2fgetting-the-lowest-value-with-key-in-array%23new-answer', 'question_page');

                                                                        );

                                                                        Post as a guest















                                                                        Required, but never shown





















































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown

































                                                                        Required, but never shown














                                                                        Required, but never shown












                                                                        Required, but never shown







                                                                        Required, but never shown







                                                                        Popular posts from this blog

                                                                        How should I support this large drywall patch? Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How do I cover large gaps in drywall?How do I keep drywall around a patch from crumbling?Can I glue a second layer of drywall?How to patch long strip on drywall?Large drywall patch: how to avoid bulging seams?Drywall Mesh Patch vs. Bulge? To remove or not to remove?How to fix this drywall job?Prep drywall before backsplashWhat's the best way to fix this horrible drywall patch job?Drywall patching using 3M Patch Plus Primer

                                                                        random experiment with two different functions on unit interval Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)Random variable and probability space notionsRandom Walk with EdgesFinding functions where the increase over a random interval is Poisson distributedNumber of days until dayCan an observed event in fact be of zero probability?Unit random processmodels of coins and uniform distributionHow to get the number of successes given $n$ trials , probability $P$ and a random variable $X$Absorbing Markov chain in a computer. Is “almost every” turned into always convergence in computer executions?Stopped random walk is not uniformly integrable

                                                                        Lowndes Grove History Architecture References Navigation menu32°48′6″N 79°57′58″W / 32.80167°N 79.96611°W / 32.80167; -79.9661132°48′6″N 79°57′58″W / 32.80167°N 79.96611°W / 32.80167; -79.9661178002500"National Register Information System"Historic houses of South Carolina"Lowndes Grove""+32° 48' 6.00", −79° 57' 58.00""Lowndes Grove, Charleston County (260 St. Margaret St., Charleston)""Lowndes Grove"The Charleston ExpositionIt Happened in South Carolina"Lowndes Grove (House), Saint Margaret Street & Sixth Avenue, Charleston, Charleston County, SC(Photographs)"Plantations of the Carolina Low Countrye