<!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>
2022-08-31
? ??
? ?arr.sort(function(a,b){return a.length - b.length;}).forEach(item=>{
? ? ? ?if(!item.includes('#') && !item.includes('&')){
? ? ? ? ? ?document.write(item+'<br><br><br>');
? ? ? ?}
? ?})
2022-02-28
默認排序順序是根據字符串UniCode碼。因為排序是按照字符串UniCode碼的順序進行排序的,所以首先應該把數組元素都轉化成字符串(如有必要),以便進行比較。
搜索
復制
2022-02-27
它只是對時間復雜度進行排序,假如遇到**##這類的,就不適用了