Definition 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:
Parameter list:
註:如果此參數為一個空字串"",那麼stringObject中的每個字元都會被分割
limit 可選。設定字串被分割的次數,如果省略此參數,則不限制分割次數。
實例碼:
使用子字串「、」作為分隔符號分割字串,此分隔符號不會成為陣列元素的一部分或陣列元素的一員。輸出結果:a,b,c,d,e。
限定的了字串分割的次數,也就是限制了傳回數組的維數。輸出結果:2。
使用空字串作為分隔符,那麼字串中的每個字元都會被分割。輸出結果:a,、,b,、,c,、,d,、,e。
以上內容是小編跟大家介紹的JavaScript Split()方法的相關知識,希望大家喜歡。