简体   繁体   中英

java script Sort method is not working on IE8?

i am working on google maps api in this i am doing sorting using sort function it is working fine in all browsers but on IE 8 it is not working properly. on console log i have seen it is returning a value "Undefined". can anybody give an idea or any alternate of sort method. Here is a part of my code.

        var branch= source.sort(function(a, b){
            return a.distance - b.distance;
        });
        return branch[0];

Try this

source.sort(function(a, b){
            return a.distance==b.distance?0:(a.distance>b.distance?1:-1);
        });
return source[0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM