search

Home  >  Q&A  >  body text

JavaScript sorts numbers in an array in order of size

I am a newbie who just started learning, and I don’t know much. During my study, I found that the arrays are not completely arranged in size order when sorted using sort(). It has something to do with the number of digits, so I thought that I I tried to arrange the array in order from small to large, and typed some code myself, but in the end there was still a problem. Please explain and correct me.%

刘虎刘虎1845 days ago1351

reply all(3)I'll reply

  • 卢小强

    卢小强2019-11-02 13:50:15

    It is recommended that if you want to write sorting by yourself, you can download the sorting method on Baidu. I personally recommend bubble sorting method.

    reply
    0
  • 刘虎

    I know there must be a way to see it, because I don’t know much now. What I’ve made with my skills is like the one above. I don’t know what’s wrong with it.

    刘虎 · 2019-11-02 13:52:06
  • 卢小强

    卢小强2019-11-02 13:49:12

    <script>function myFunction(){	var fruits = ["21421", "421421", "Apple", "Mango"];	fruits.sort();	var x=document.getElementById("demo");	x.innerHTML=fruits;}</script>
    I tried it and there seems to be no problem


    reply
    0
  • Cancelreply