JS零碎小知識

來源:互聯網
上載者:User

標籤:org   正則表達   div   sort   data   func   write   大於   字串數組   

filter()方法對數組進行過濾,產生新數組var aqiNewData = aqiData.filter(function(data){return data[1]>60;}); //對大於60的資料群組成新數組。sort()方法對新數組進行從大到小排序。aqiNewData.sort(function(a,b){return b[1] - a[1];}); //若換成a[1] - b[1]則是從小到大排序。createDocumentFragment()建立虛擬(片段)節點的方法可以更安全改變文檔的結構及節點 。之後將此節點追加到父節點即可。replace(a,b) 方法用於在字串中用一些字元替換另一些字元,或替換一個與Regex匹配的子串。將a替換成b,ab可以為字串。split( ) 方法用於把一個字串分割成字串數組。<script type="text/javascript">var str="How are you doing today?"document.write(str.split(" ") + "<br />")document.write(str.split("") + "<br />")document.write(str.split(" ",3))</script>輸出結果:How,are,you,doing,today?H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?How,are,you join( ) 方法用於把數組中的所有元素放入一個字串。元素是通過指定的分隔字元進行分隔的。<script type="text/javascript">var arr = new Array(3)arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr.join())</script>輸出:George,John,Thomas若改為join(‘ ‘) 則輸出結果為 George John Thomas

JS零碎小知識

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.