Home How to sort an array of integers correctly
Reply: 0

How to sort an array of integers correctly

user702
1#
user702 Published in July 23, 2018, 1:40 pm

Trying to get the highest and lowest value from an array that I know will contain only integers seems to be harder than I thought.

var numArray = [140000, 104, 99];
numArray = numArray.sort();
alert(numArray)

I'd expect this to show 99, 104, 140000. Instead it shows 104, 140000, 99. So it seems the sort is handling the values as strings.

Is there a way to get the sort function to actually sort on integer value?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.459004 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO