JavaScript Split()方法_javascript技巧
May 16, 2016 pm 03:24 PMDefinition and usage of split() method:
Thesplit() method can use the substring of the string as a delimiter to split the string into a string array and return this array.
Note: The substring used as a delimiter will not become part of the elements of the returned array or a member of the array elements.
Here we only introduce the use of ordinary characters as separators. For information on using regular expressions as separators, please refer to the regular expression split() function chapter.
Click to see more related String object methods and properties.
Grammar structure:
stringObject.split(separator,limit)
Parameter list:
註:如果此參數為一個空字串"",那麼stringObject中的每個字元都會被分割
limit 可選。設定字串被分割的次數,如果省略此參數,則不限制分割次數。
實例碼:
var a="a、b、c、d、e";
console.log(a.split("、"));
使用子字串「、」作為分隔符號分割字串,此分隔符號不會成為陣列元素的一部分或陣列元素的一員。輸出結果:a,b,c,d,e。
var a="a、b、c、d、e";
console.log(a.split("、",2));
限定的了字串分割的次數,也就是限制了傳回數組的維數。輸出結果:2。
var a="a、b、c、d、e";
console.log(a.split(""));
使用空字串作為分隔符,那麼字串中的每個字元都會被分割。輸出結果:a,、,b,、,c,、,d,、,e。
以上內容是小編跟大家介紹的JavaScript Split()方法的相關知識,希望大家喜歡。

熱門文章

熱門文章

熱門文章標籤

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)