编写Javascript脚本
编写Javascript脚本,为一个无序的数组排序,并输出排序后的数组。注意:数组元素的值自己定义。...
编写Javascript脚本,为一个无序的数组排序,并输出排序后的数组。注意:数组元素的值自己定义。
展开
1个回答
展开全部
var a=[3,7,4,334,34,66,77,343,33,109,32,67];
var b=["abc","cde","f","g","b","z","acd"];
alert("排序前:\n" + a + "\n排序后:\n" + a.sort(function(x,y){if(x==y)return 0;else return x>y?1:-1;}));
alert("排序前:\n" + b + "\n排序后:\n" + b.sort(function(x,y){if(x==y)return 0;else return x>y?1:-1;}));
var b=["abc","cde","f","g","b","z","acd"];
alert("排序前:\n" + a + "\n排序后:\n" + a.sort(function(x,y){if(x==y)return 0;else return x>y?1:-1;}));
alert("排序前:\n" + b + "\n排序后:\n" + b.sort(function(x,y){if(x==y)return 0;else return x>y?1:-1;}));
参考资料: http://camen.cosbeauty.net
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询