字符串这样直接.sort()排序会有什么问题吗?
<!DOCTYPE HTML> <html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>数组</title> <script type="text/javascript"> //创建数组 var arr = ['*','##',"***","&&","****","##*"]; arr[7] = "**"; //显示数组长度 alert(arr.length); //将数组内容输出,完成达到的效果。 var arr2 = arr.filter(item=> /^[*]+/.test(item)); arr2.sort(); for(let i=0; i<arr2.length; i++){ document.write(arr2[i]+'<br>'); } </script> </head> <body> </body> </html>