'use strict' var resultValue=[ '武汉' , '北京' , '上海' , '天津' ] ; resultValue= resultValue.sort( function compareFunction(param1,param2){ return param1.localeCompare(param2,'zh-CN'); } ); console.log(resultValue); var citys = ['北京-b','上海-s','广州-g','深圳-s','南京-n','苏州-s','杭州-h','济南-j','青岛-q','武汉-w','沈阳-sh','成都-ch','天津-t','重庆-ch','西安-x','郑州-zh','石家庄-sh','长沙-ch','长春-ch','合肥-h','福州-f']; function sortRule(a,b) { return a.localeCompare(b,'ch-CH');
} window.onload = function(){ console.log(citys.sort(sortRule)); }
|