Hướng dẫn what does split do in javascript? - Chia tách làm gì trong javascript?

Phương thức

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
3 lấy một mẫu và chia
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
4 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.
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
3
method takes a pattern and divides a
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
4 into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.

Thử nó

Cú pháp

split()
split(separator)
split(separator, limit)

Thông số

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 Tùy chọnOptional

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

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
6 - 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.

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
7 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

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 được chỉ định, nhưng dừng khi các mục
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
7 đã đượ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
    "😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
    "😄😄".split(/(?:)/u); // [ "😄", "😄" ]
    
    7 nếu kết thúc của chuỗi đạt được trước khi đạt đến giới hạn.
  • Nếu
    "😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
    "😄😄".split(/(?:)/u); // [ "😄", "😄" ]
    
    7 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));
    // []
    
    2,
    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));
    // []
    
    3 đượ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));
// []
4 của chuỗi, được chia tại mỗi điểm xảy ra
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 trong chuỗi đã cho.

Sự mô tả

Nếu

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 là một chuỗi không trống, chuỗi đích được phân chia bởi tất cả các trận đấu của
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 mà không bao gồm
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 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ư
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. Nếu
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 chứa nhiều ký tự, toàn bộ chuỗi ký tự đó phải được tìm thấy để phân chia. Nếu
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 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
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 không xảy ra trong
function splitString(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)
3, mảng được trả về chứa một phần tử bao gồm toàn bộ chuỗi.

Nếu

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 là một chuỗi trống (
function splitString(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)
5),
function splitString(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)
3 đượ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 đó,

function splitString(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 là cách duy nhất để tạo ra một mảng trống khi một chuỗi được truyền là
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5.
function splitString(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 is therefore the only way to produce an empty array when a string is passed as
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5.

Nếu

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 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
0 được đặt.

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]

Nếu

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 là biểu thức chính quy với các nhóm bắt giữ, thì mỗi lần
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 khớp, 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
3 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
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
6 của RegEXP.

Nếu

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 là một đối tượng có phương thức
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
6, phương thức đó được gọi với chuỗi đích và
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
7 làm đối số và
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
8 được đặt thành đối tượng. Giá trị trả về của nó trở thành giá trị trả về của
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.

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,

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
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

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5. 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ẻ.

function splitString(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

Loại bỏ khoảng trắng khỏi chuỗi

Trong ví dụ sau,

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
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)
3 là mảng được trả về do
"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
3.

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", "" ]

Trả lại một số lượng hạn chế các phân tách

Trong ví dụ sau,

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
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 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) 6 để bao gồm các phần của dấu tách trong kết quả

Nếu

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
5 là một biểu thức chính quy chứa thu thập dấu ngoặc đơn
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)
8
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)
9, kết quả phù hợp được bao gồm trong mảng.

const myString = 'Hello 1 word. Sentence number 2.'
const splits = myString.split(/(\d)/)

console.log(splits)

Tập lệnh này hiển thị như sau:

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
0

Chia tách vớ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)
6 để bao gồm các phần của dấu 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 matches the character class for digits between 0 and 9.

Nếu "😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ] "😄😄".split(/(?:)/u); // [ "😄", "😄" ] 5 là một biểu thức chính quy chứa thu thập dấu ngoặc đơn 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) 8 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) 9, 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", "" ]
0 khớp với lớp ký tự cho các chữ số từ 0 đến 9.

Sử dụng bộ chia tùy chỉnh

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
1

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.

"😄😄".split(/(?:)/); // [ "\ud83d", "\ude04", "\ud83d", "\ude04" ]
"😄😄".split(/(?:)/u); // [ "😄", "😄" ]
2

Thông số kỹ thuật

Sự chỉ rõ
Đặc tả ngôn ngữ Ecmascript # sec-string.prototype.split
# sec-string.prototype.split

Tính tương thích của trình duyệt web

Bảng BCD chỉ tải trong trình duyệt

Xem thêm

Những gì được phân chia được sử dụng cho?

Định nghĩa và cách sử dụng. Phương thức chia () chia một chuỗi vào một danh sách. Bạn có thể chỉ định phân tách, dấu phân cách mặc định là bất kỳ khoảng trắng nào. Lưu ý: Khi MaxSplit được chỉ định, danh sách sẽ chứa số lượng phần tử được chỉ định cộng với một.splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.

Tầm quan trọng của hàm split () là gì?

Chức năng phân chia trả về một danh sách các chuỗi sau khi chia chuỗi dựa trên dấu phân cách đã cho. Sau đây là những lợi thế của việc sử dụng hàm chia trong Python: Tại một số điểm, chúng ta có thể phải chia một chuỗi lớn thành các khối hoặc chuỗi nhỏ hơn. Nó trái ngược với sự kết hợp, cộng thêm hai chuỗi lại với nhau.At some point we may have to break down a large string into smaller chunks or strings. It is the opposite of concatenation, which adds two strings together.

Những gì được chia trong mã hóa?

Tách mã là sự phân chia mã thành các gói hoặc thành phần khác nhau sau đó có thể được tải theo yêu cầu hoặc song song.Khi một ứng dụng phát triển về độ phức tạp hoặc được duy trì, các tệp hoặc gói JavaScripts phát triển theo kích thước byte, đặc biệt là khi số lượng và kích thước của các thư viện bên thứ ba bao gồm tăng lên.the splitting of code into various bundles or components which can then be loaded on demand or in parallel. As an application grows in complexity or is maintained, CSS and JavaScripts files or bundles grow in byte size, especially as the number and size of included third-party libraries increases.

Làm thế nào để bạn chia một biểu thức JavaScript?

Để phân chia một chuỗi bằng một biểu thức chính quy, hãy chuyển regex làm tham số cho phương thức chia (), ví dụ:str.chia (/[, \ s]/).Phương thức phân chia lấy một chuỗi hoặc biểu thức chính quy và chia chuỗi dựa trên dấu phân cách được cung cấp, thành một mảng của các chuỗi con.pass a regex as a parameter to the split() method, e.g. str. split(/[,. \s]/) . The split method takes a string or regular expression and splits the string based on the provided separator, into an array of substrings.