In the web applications we develop, processing strings is the most commonly used function, this post will introduce : ① How to replace Javascript strings? ② How to split a string to generate an array? ③ How to slice a string by index?
Keywords: Javascript , strings , replace , split , slice.
Replace
In Javascript, replacing the content of a string requires the use of the replace() function. Here are a few common examples.
Split
In Javascript, splitting a string needs to use the split() function, and specify what character to split according to, the function returns an array.
Slice
In Javascript, you need to use slice(start, end) function to intercept a string, where start represents the start-offset and end represents the end-offset.
In Javascript, we can use replace(), split(), slice() functions to replace, split, and intercept strings respectively. The result type returned by split() is array. For other operations of array type, please read related articles.