hãy để văn bản = "hôm nay bạn thế nào?"; const myArray = text.split (""); const myArray = text.split(" ");
Hãy tự mình thử »
Chia các từ và trả lại từ thứ hai:
hãy để văn bản = "hôm nay bạn thế nào?"; const myArray = text.split (""); Đặt từ = myarray [1]; const myArray = text.split(" "); let word = myArray[1];
Hãy tự mình thử »
Chia các từ và trả lại từ thứ hai:
hãy để văn bản = "hôm nay bạn thế nào?"; const myArray = text.split (""); Đặt từ = myarray [1];
Hãy tự mình thử »
Chia các từ và trả lại từ thứ hai:
hãy để văn bản = "hôm nay bạn thế nào?"; const myArray = text.split (""); Đặt từ = myarray [1];
Hãy tự mình thử »
Chia các từ và trả lại từ thứ hai:
hãy để văn bản = "hôm nay bạn thế nào?"; const myArray = text.split (""); Đặt từ = myarray [1];
Chia các ký tự, bao gồm cả khoảng trắng:
const myArray = text.split ("");
Sử dụng tham số giới hạn:
const myArray = text.split ("", 3);
Thêm ví dụ dưới đây.
Định nghĩa và cách sử dụng
Phương thức "😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
3 chia một chuỗi thành một mảng các chuỗi con.
Các mô hình mô tả nơi mỗi sự phân chia nên xảy ra. Có thể là một chuỗi hoặc một đối tượng có phương thức
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
0 - ví dụ điển hình là một biểu thức chính quy. Nếu không xác định, chuỗi mục tiêu ban đầu được trả về trong một mảng.
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
1 Tùy chọnOptional
Một số nguyên không âm chỉ định giới hạn về số lượng chuỗi con được đưa vào mảng. Nếu được cung cấp, hãy chia chuỗi ở mỗi lần xuất hiện của
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
1 đã được đặt trong mảng. Bất kỳ văn bản còn sót lại không được bao gồm trong mảng.
Mảng có thể chứa ít mục hơn so với
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
1 nếu kết thúc của chuỗi đạt được trước khi đạt đến giới hạn.
Nếu
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
1 là
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
6,
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
7 được trả về.
Giá trị trả về
Một
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
9 trong kết quả. Ví dụ: một chuỗi chứa các giá trị phân tách (TSV) có thể được phân tích cú pháp bằng cách chuyển một ký tự tab dưới dạng dấu phân cách, như
functionsplitString(stringToSplit, separator){const arrayOfStrings = stringToSplit.split(separator)
console.log('The original string is: ', stringToSplit)
console.log('The separator is: ', separator)
console.log('The array has ', arrayOfStrings.length,' elements: ', arrayOfStrings.join(' / '))}const tempestString ='Oh brave new world that has such people in it.'const monthString ='Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'const space =' 'const comma =','splitString(tempestString, space)splitString(tempestString)splitString(monthString, comma)
9 xuất hiện ở đầu (hoặc kết thúc) của chuỗi, nó vẫn có tác dụng phân tách, dẫn đến chuỗi trống (tức là độ dài bằng 0) xuất hiện ở vị trí đầu tiên (hoặc cuối cùng) của mảng được trả về. Nếu
functionsplitString(stringToSplit, separator){const arrayOfStrings = stringToSplit.split(separator)
console.log('The original string is: ', stringToSplit)
console.log('The separator is: ', separator)
console.log('The array has ', arrayOfStrings.length,' elements: ', arrayOfStrings.join(' / '))}const tempestString ='Oh brave new world that has such people in it.'const monthString ='Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'const space =' 'const comma =','splitString(tempestString, space)splitString(tempestString)splitString(monthString, comma)
7, mảng được trả về chứa một phần tử bao gồm toàn bộ chuỗi.
functionsplitString(stringToSplit, separator){const arrayOfStrings = stringToSplit.split(separator)
console.log('The original string is: ', stringToSplit)
console.log('The separator is: ', separator)
console.log('The array has ', arrayOfStrings.length,' elements: ', arrayOfStrings.join(' / '))}const tempestString ='Oh brave new world that has such people in it.'const monthString ='Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'const space =' 'const comma =','splitString(tempestString, space)splitString(tempestString)splitString(monthString, comma)
9),
functionsplitString(stringToSplit, separator){const arrayOfStrings = stringToSplit.split(separator)
console.log('The original string is: ', stringToSplit)
console.log('The separator is: ', separator)
console.log('The array has ', arrayOfStrings.length,' elements: ', arrayOfStrings.join(' / '))}const tempestString ='Oh brave new world that has such people in it.'const monthString ='Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'const space =' 'const comma =','splitString(tempestString, space)splitString(tempestString)splitString(monthString, comma)
7 được chuyển đổi thành một mảng của mỗi "ký tự" UTF-16 của nó, mà không có chuỗi trống ở hai đầu của chuỗi kết quả.
Lưu ý: Do đó,
The original string is: "Oh brave new world that has such people in it."
The separator is: " "
The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it.
The original string is: "Oh brave new world that has such people in it."
The separator is: "undefined"
The array has 1 elements: Oh brave new world that has such people in it.
The original string is: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
The separator is: ","
The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec
1 là cách duy nhất để tạo ra một mảng trống khi một chuỗi được truyền là
The original string is: "Oh brave new world that has such people in it."
The separator is: " "
The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it.
The original string is: "Oh brave new world that has such people in it."
The separator is: "undefined"
The array has 1 elements: Oh brave new world that has such people in it.
The original string is: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
The separator is: ","
The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec
1 is therefore the only way to produce an empty array when a string is passed as
9 là một regexp phù hợp với các chuỗi trống, liệu trận đấu có được chia bằng các đơn vị mã UTF-16 hay các codepoint Unicode phụ thuộc vào việc cờ
The original string is: "Oh brave new world that has such people in it."
The separator is: " "
The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it.
The original string is: "Oh brave new world that has such people in it."
The separator is: "undefined"
The array has 1 elements: Oh brave new world that has such people in it.
The original string is: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
The separator is: ","
The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec
9 khớp với nhau, các nhóm bị bắt (bao gồm bất kỳ kết quả
The original string is: "Oh brave new world that has such people in it."
The separator is: " "
The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it.
The original string is: "Oh brave new world that has such people in it."
The separator is: "undefined"
The array has 1 elements: Oh brave new world that has such people in it.
The original string is: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
The separator is: ","
The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec
7 nào) được ghép vào mảng đầu ra. Hành vi này được chỉ định bằng phương pháp
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
0, phương thức đó được gọi với chuỗi đích và
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
1 làm đối số và
const names ='Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand '
console.log(names)const re =/\s*(?:;|$)\s*/const nameList = names.split(re)
console.log(nameList)
2 được đặt thành đối tượng. Giá trị trả về của nó trở thành giá trị trả về của
const names ='Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand '
console.log(names)const re =/\s*(?:;|$)\s*/const nameList = names.split(re)
console.log(nameList)
3.
Bất kỳ giá trị nào khác sẽ được ép buộc vào một chuỗi trước khi được sử dụng làm dấu phân cách.
Ví dụ
Sử dụng Split ()
Khi chuỗi trống và không có dấu tách nào được chỉ định,
3 trả về một mảng chứa một chuỗi trống, thay vì một mảng trống. Nếu chuỗi và phân tách đều là các chuỗi trống, một mảng trống được trả về.
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
Ví dụ sau đây xác định một hàm chia chuỗi thành một mảng các chuỗi bằng cách sử dụng
9. Sau khi chia chuỗi, các thông báo nhật ký hàm chỉ ra chuỗi gốc (trước khi phân chia), bộ phân cách được sử dụng, số lượng phần tử trong mảng và các phần tử mảng riêng lẻ.
functionsplitString(stringToSplit, separator){const arrayOfStrings = stringToSplit.split(separator)
console.log('The original string is: ', stringToSplit)
console.log('The separator is: ', separator)
console.log('The array has ', arrayOfStrings.length,' elements: ', arrayOfStrings.join(' / '))}const tempestString ='Oh brave new world that has such people in it.'const monthString ='Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'const space =' 'const comma =','splitString(tempestString, space)splitString(tempestString)splitString(monthString, comma)
Ví dụ này tạo ra đầu ra sau:
The original string is: "Oh brave new world that has such people in it."
The separator is: " "
The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it.
The original string is: "Oh brave new world that has such people in it."
The separator is: "undefined"
The array has 1 elements: Oh brave new world that has such people in it.
The original string is: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
The separator is: ","
The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec
3 tìm kiếm không gian hoặc nhiều không gian, theo sau là dấu chấm phẩy, theo sau là không có hoặc nhiều không gian hơn và khi tìm thấy, loại bỏ các không gian và dấu chấm phẩy khỏi chuỗi.
const names ='Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand '
console.log(names)const re =/\s*(?:;|$)\s*/const nameList = names.split(re)
console.log(nameList)
const names ='Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand '
console.log(names)const re =/\s*(?:;|$)\s*/const nameList = names.split(re)
console.log(nameList)
Điều này ghi lại hai dòng; Dòng đầu tiên ghi lại chuỗi ban đầu và dòng thứ hai ghi lại mảng kết quả.
Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
3 tìm khoảng trống trong một chuỗi và trả về 3 lần chia đầu tiên mà nó tìm thấy.
const myString ='Hello World. How are you doing?'const splits = myString.split(' ',3)
console.log(splits)
Tập lệnh này hiển thị như sau:
["Hello","World.","How"]
Chia tách với Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
0 để bao gồm các phần của bộ tách trong kết quả
Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
0 để bao gồm các phần của bộ tách trong kết quả
Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
4 matches the character class for digits between 0 and 9.
Nếu "😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
9 là một biểu thức chính quy chứa thu thập dấu ngoặc đơn Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
2 Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
3, kết quả phù hợp được bao gồm trong mảng.
Lưu ý:
Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
const emptyString ='';// string is empty and no separator is specified
console.log(emptyString.split());// [""]// string and separator are both empty strings
console.log(emptyString.split(emptyString));// []
0 có thể được sử dụng như một bộ chia với hành vi tùy chỉnh.
Ví dụ sau đây phân tách một chuỗi bằng trạng thái bên trong bao gồm số tăng:
Ví dụ sau đây sử dụng trạng thái nội bộ để thực thi một số hành vi nhất định và để đảm bảo kết quả "hợp lệ" được tạo ra.
Thông số kỹ thuật # sec-string.prototype.split
Sự chỉ rõ
Đặc tả ngôn ngữ Ecmascript # sec-string.prototype.split
Tính tương thích của trình duyệt web
Làm thế nào để bạn chia một cái gì đó trong JavaScript?
Phương thức Split () chia một chuỗi thành một mảng các chuỗi con. Phương thức chia () trả về mảng mới. Phương thức chia () không thay đổi chuỗi gốc. Nếu ("") được sử dụng làm dấu phân cách, chuỗi được phân chia giữa các từ.. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
Làm thế nào để bạn chia các yếu tố?
Các yếu tố phân chia..
Nhấp vào sửa đổi bảng điều chỉnh tab (phần tử chia) ..
Nếu muốn, trên thanh Tùy chọn, chọn Xóa phân đoạn bên trong.Khi bạn chọn tùy chọn này, Revit sẽ xóa phân đoạn của bức tường hoặc đường giữa các điểm đã chọn ..
Nhấp vào phần tử tại điểm bạn muốn chia ..
Làm thế nào để bạn chia một biểu tượng trong JavaScript?
Demo JavaScript: Symbol.Split..
lớp Split1 {.
constructor (value) {.
đây.giá trị = giá trị ;.
[Biểu tượng.tách] (chuỗi) {.
const index = chuỗi.indexof (giá trị này) ;.
Trả về `$ {this.Giá trị} $ {chuỗi.chuỗi con (0, index)}/$ {chuỗi.Subrtr (index + this. Giá trị. Độ dài)} `;.
Làm thế nào để chức năng phân chia hoạt động trong JavaScript?
Chia () phương thức chia () lấy một mẫu và chia một chuỗi thành một danh sách các chuỗi con được đặt hàng bằng cách tìm kiếm mẫu, đặt các chuỗi con này vào một mảng và trả về mảng.takes a pattern and divides a String into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.